필터 지우기
필터 지우기

Saving a structure to Excel

조회 수: 30 (최근 30일)
Gareth Pritchard
Gareth Pritchard 2014년 10월 13일
댓글: raghvendra deshpande 2018년 3월 6일
I have a simple (albeit large) structure that follows the pattern Year.Variable.Month.TimeSlot
There are 8 TimeSlot values, and when opened each one displays a 16x1 array. I'm looking for something that will enable me to save all 8 of these values into excel (i.e. saving a single month of data). If there was a way to save each month onto the same Excel file, this would be great, however I don't mind a little manual cutting and pasting to put all the months together on a single sheet.
Any help would be massively appreciated.

채택된 답변

David Sanchez
David Sanchez 2014년 10월 13일
Try this out (adapt it to your need)
a.b.c.d = rand(16,1);
a.b.c.e = rand(16,1);
my_last_field = fieldnames(a.b.c);
% write the last field values in a single matrix
L = numel(my_last_field);
my_data = zeros(16,L);
for k=1:L
my_data(:,k) = a.b.c.(my_last_field{k});
end
% write the matrix to excell sheet
xlswrite('text.xls',my_data)
  댓글 수: 1
Gareth Pritchard
Gareth Pritchard 2014년 10월 13일
This was a great help, thanks!

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

추가 답변 (2개)

David Sanchez
David Sanchez 2014년 10월 13일
take a look at this linK:
Where is clearly stated:
You may need to use struct2cell() to convert your structure to cell array and then use xlswrite(). Please give an example of your structure. There might be special things to deal with.
  댓글 수: 1
Gareth Pritchard
Gareth Pritchard 2014년 10월 13일
편집: Gareth Pritchard 2014년 10월 13일
Thanks, but I've tried using that and it's not much help. Basically I'm looking to save the last field in Excel for the entire structure

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


Anmol Pardeshi
Anmol Pardeshi 2018년 2월 9일
If struct to cell and then conversion is a problem, you can individually collect the fields and their values in a matrix (table) and then export it to excel. I have a struct with 8 field and the last field has a string matrix of n-by-2 dimension. the way I solved this problem was - a. start a new matrix (table) b. collect the 1st, 2nd, 3rd field in cols 1/2/3 rectvly., of this new table. c. in the 4th & 5th col, I copied the n-by-2 (or essentially the 2 cols of last field in struct corresponded to the last 2 cols of the new table)
the new table is ought to increase in length because it becomes something like a table that expands in the last col i.e. something like the diagram of the FFT butterfly.
I can share the code if anyone needs it. :)
  댓글 수: 1
raghvendra deshpande
raghvendra deshpande 2018년 3월 6일
Yes .. Please share the code

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

카테고리

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