xlswrite many data arrays into excel

조회 수: 1 (최근 30일)
JB
JB 2017년 8월 24일
댓글: JB 2017년 8월 25일
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
  댓글 수: 1
JB
JB 2017년 8월 25일
Thanks Jan Simon. Works great

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by