Saving a structure to Excel
29 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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)
更多回答(2 个)
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.
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. :)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!