Write 10 excel for loop
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Now I have one original.xlsx, I want to write Data in Sheet1 from E1.
xlswrite('Original.xlsx',Data,'Sheet1','E1')
How do I write 10 different Data{#} into Original.xlsx as different excel name, all in Sheet1 from E1.
for i=1:10
xlswrite('Original.xlsx',Data{i},'Sheet1','E1')?
2 Commenti
Walter Roberson
il 4 Mar 2016
To confirm, you want to produce just one output file, right? Do you want the ten in different sheets, or do you want them to go into E1 then E2 then E3 and so on? Or do you want the first to start at E1 and then the second to be in E but below where-ever the first finished? Or ...?
Risposta accettata
Walter Roberson
il 4 Mar 2016
filenames = {'January.xlsx', 'February.xlsx', 'Cheezburger.xlsx', 'Durango95.xlsx', 'EschewObfuscation.xlsx', ....};
for i=1:10
xlswrite(filenames{i}, Data{i}, 'Sheet1','E1');
end
3 Commenti
Walter Roberson
il 4 Mar 2016
I am not sure what you mean; perhaps you mean something like,
filenames = {'January.xlsx', 'February.xlsx', 'Cheezburger.xlsx', 'Durango95.xlsx', 'EschewObfuscation.xlsx', ....};
[~, ~, orig_raw] = xlsread('Original.xlsx', 'Sheet1');
for i=1:10
xlswrite(filenames{i}, orig_raw, 'Sheet1');
xlswrite(filenames{i}, Data{i}, 'Sheet1','E1');
end
However if you were going to do that then I would use
filenames = {'January.xlsx', 'February.xlsx', 'Cheezburger.xlsx', 'Durango95.xlsx', 'EschewObfuscation.xlsx', ....};
[~, ~, orig_raw] = xlsread('Original.xlsx', 'Sheet1');
for i=1:10
outdata = orig_raw;
new_data = Data{i};
outdata(1:length(new_data),5) = new_data;
xlswrite(filenames{i}, outdata, 'Sheet1');
end
Note: if Data{i} a numeric vector then you would use
for i=1:10
outdata = orig_raw;
new_data = num2cell(Data{i});
outdata(1:length(new_data),5) = new_data;
xlswrite(filenames{i}, outdata, 'Sheet1');
end
But if Data{i} is a numeric scalar or string then you would use
for i=1:10
outdata = orig_raw;
new_data = Data{i};
outdata{1,5} = new_data;
xlswrite(filenames{i}, outdata, 'Sheet1');
end
Più risposte (1)
Joachim Schlosser
il 4 Mar 2016
You can write the whole cell array at once. See the cell array example in the online help: http://www.mathworks.com/help/releases/R2015b/matlab/ref/xlswrite.html
If you are asking about the for loop because you first are calculating each cell before writing, I'd advise to export to Excel in a separate step after the loop for performance reasons.
0 Commenti
Vedere anche
Categorie
Scopri di più su Spreadsheets in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!