MATLAB Answers

xlswrite many data arrays into excel

조회 수: 15(최근 30일)
JB 24 Aug 2017
Commented: JB 25 Aug 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???

  댓글 수: 0

로그인 to comment.

채택된 답변

Jan 24 Aug 2017
Jan 님이 편집함. 24 Aug 2017
You find many threads concerning this problem in the forum. See 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');

  댓글 수: 1

JB 25 Aug 2017
Thanks Jan Simon. Works great

로그인 to comment.

More Answers (0)

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by