Borrar filtros
Borrar filtros

xlswrite many data arrays into excel

1 visualización (últimos 30 días)
JB
JB el 24 de Ag. de 2017
Comentada: JB el 25 de Ag. de 2017
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???

Respuesta aceptada

Jan
Jan el 24 de Ag. de 2017
Editada: Jan el 24 de Ag. de 2017
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

Más respuestas (0)

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by