MATLAB: Write in multiple rows in excel

different rowsexcel

Hello everyone, I have a loop (n=30), each loop gives me different results. I want to write the result of the first loop at the first row in an excel sheet, and when the code goes to the next loop it will give me another set of results and I need these new results to be written at the second row in the excel sheet and the same for the last loop (n=30). I wonder if that possible in the matlab. Thanks in advance.

Best Answer

Yes. Let's say that you have 100 results at each iteration stored in a row vector. Try this
allResults = zeros(30, 100);
for k = 1 : size(allResults, 1)
theseResults = .... some row vector that you generate somehow ....
allResults(k, :) = theseResults;
end
xlswrite(xlFileName, allResults);
Basically you build up a matrix one row at a time then write the thing all at once in one single call to xlswrite().