How do I generate the range of data to be written to in an excel sheet dynamically when using XLSWRITE in a loop in MATLAB 7.9 (R2009b) ?

I would like to write to a new range of data cells in an excel sheet, based on the loop index (with a for loop), dynamically.

Answers (2)

GENVARNAME can be used to dynamically generate the range of cells to which data is written, in the following manner:
A = [1 2 3; 4 5 6]
for i = 1:2
varname = genvarname(['A' i]);
xlswrite('testing.xls',A(i,:),'Sheet1',varname);
end
If it helps, I just published a function on the File Exchange that will enable you to calculate Excel ranges if you know your start cell (or range), the row and column offsets and the row/column size you want. http://www.mathworks.com/matlabcentral/fileexchange/30180-calculate-excel-range

Products

Asked:

on 16 Jan 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!