How to use xlswrite with cell arrays in a loop?

1 vue (au cours des 30 derniers jours)
gsourop
gsourop le 17 Jan 2019
Commenté : gsourop le 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?

Réponse acceptée

Jan
Jan le 17 Jan 2019
Modifié(e) : Jan le 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 commentaire
gsourop
gsourop le 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by