xlswrite many data arrays into excel

1 次查看(过去 30 天)
Please help, i am new to matlab GUI coding. I have many dataarray such as
set1={'year' 'date' 'day' 'time'; '2017' '0803' 'Monday' '15.15'; '2015' '0303' 'Tuesday' '08.20'}
set2={'year' 'date' 'day' 'time'; '2016' '0705' 'Friday' '17.15'; '2013' '0310' 'Monday' '18.20'}
title={'dataset1' 'dataset2'}
The data arrays that I have is much longer (400-1000 rows) and I have about 20 different set, but the number changes dependent on the GUI data. What I want to do is automatically export this all these arrays into a single excel spreadsheet with each set as separate sheets with the sheet-title specified in the "title" string.
So far I am using
[FileNameBodeWrite, PathNameBodeWrite] = uiputfile({'*.xls'},'Save As...',
[Title{1,1} '.xls']);
([PathNameBodeWrite FileNameBodeWrite ],[Set1],1,'A1')
But that of cause only works for that specific set. I want to include them all in one spreadsheet, potentially in a loop???

采纳的回答

Jan
Jan 2017-8-24
编辑:Jan 2017-8-24
You find many threads concerning this problem in the forum. See https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval. The problem is the hidden number in the name of the variable. If you use an array instead, the solution is easy:
Data = {set1, set2}; % Better use a cell array from the beginning
Title = {'dataset1' 'dataset2'};
File = fullfile(PathNameBodeWrite, FileNameBodeWrite);
for k = 1:numel(Data)
xlswrite(File, Data{k}, Title{k}, 'A1');
end

更多回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by