如何将数据从Matlab导出到excel以进行循环? [英] How to export data from Matlab to excel for a loop?

查看:1614
本文介绍了如何将数据从Matlab导出到excel以进行循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个"for循环"代码

I have a code for "for loop"

对于我= 1:4 陈述... y = sim(net,I); 结束

for i=1:4 statement... y=sim(net, I); end

现在我需要将y的值导出到Excel工作表.为此,我用..

now i need to export the value of y to excel sheet. for that i used..

xlswrite('output_data.xls',y,'output_data','A1')

xlswrite('output_data.xls', y, 'output_data', 'A1')

但是我的问题是excel的ID(即"A1")应根据每次迭代进行更改...在我的情况下,对于迭代1-> A1,迭代-> A2等.

but my problem is that the ID of excel i.e. "A1" should change according to each iteration... in my case for iteration 1-> A1, iteration-> A2 and so on..

任何人请帮我.. 提前致谢.寻求帮助或建议.

anybody please help me out .. thanks in advance. for any assistance.. or suggestion..

推荐答案

您可以将sim输出存储在向量(y(ii))中,并且只需一次写入即可保存在工作表中.由于您执行的是一次批量写入,而不是许多次小的写入,因此这样做也更有效率.

You can store sim outputs in a vector (y(ii)) and save in the sheet with a single write. This is also more efficient since you perform a single bulk-write instead of many small writes.

指定第一个单元格,然后y将从此处开始写入.

Specify the first cell and y will be written starting from there.

last = someNumber;
for i=1:last statement... y(i)=sim(net, I); end

xlswrite('output_data.xls', y', 'output_data', 'A1');

如果您愿意指定范围,请写['A1:A',num2str(last)]而不是A1.

If you prefer specify the range write ['A1:A',num2str(last)] instead of A1.

如果您真的想在循环中编写,请尝试:

If you really want to write within the loop try:

for ii=1:last
    ...
    y=sim(net, I);
    xlswrite('output_data.xls', y, 'output_data', sprintf('A%d',ii));
end

这篇关于如何将数据从Matlab导出到excel以进行循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆