How to use xlswrite with cell arrays in a loop?

1 Ansicht (letzte 30 Tage)
gsourop
gsourop am 17 Jan. 2019
Kommentiert: gsourop am 17 Jan. 2019
Hi everyone,
Suppose that I have the following cell array:
AA = cell(10,1);
for i = 1 : 10
A = randn(20,1);
AA{i,1} = A;
end
And I want to write in Excel The rows of AA in spreadsheets j. For example,
for i=1
xlswrite('Example.xls', AA{1,1},'Sheet1','a1')
for i=2
xlswrite('Example.xls', AA{2,1},'Sheet1','b1')
and so on
How could I use a loop to avoid re-writing the same command 10 times?

Akzeptierte Antwort

Jan
Jan am 17 Jan. 2019
Bearbeitet: Jan am 17 Jan. 2019
for k = 1:10
Range = [char('a' + k - 1), '1']
xlswrite('Example.xls', AA{k,1}, 'Sheet1', Range)
end
The conversion to the Excel range fails for more than 27 columns. Prefer a stable function instead, e.g. https://www.mathworks.com/matlabcentral/fileexchange/58917-getexcelrange-rowlimits-columnlimits
  1 Kommentar
gsourop
gsourop am 17 Jan. 2019
Thank you for your answer!
However, this command can support only up to 'z', whereas Excel contains columns AA, AB etc.. . So, if AA is a cell(32,1) and i = 1:32, for example, I cannot generalize this command.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by