Azzera filtri
Azzera filtri

How to use xlswrite with cell arrays in a loop?

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Jan
Jan il 17 Gen 2019
Modificato: Jan il 17 Gen 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 Commento
gsourop
gsourop il 17 Gen 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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by