Saving a structure to Excel
74 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gareth Pritchard
am 13 Okt. 2014
Kommentiert: raghvendra deshpande
am 6 Mär. 2018
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.
0 Kommentare
Akzeptierte Antwort
David Sanchez
am 13 Okt. 2014
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)
Weitere Antworten (2)
David Sanchez
am 13 Okt. 2014
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 Kommentar
Anmol Pardeshi
am 9 Feb. 2018
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 Kommentar
Siehe auch
Kategorien
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!