How to export data from Matlab to excel for a loop?

后端 未结 3 938
旧时难觅i
旧时难觅i 2021-01-03 15:26

I have a code for \"for loop\"

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

now

3条回答
  •  抹茶落季
    2021-01-03 16:12

    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.

    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');
    

    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
    

提交回复
热议问题