struct with timeseries fields to Excel
6 次查看(过去 30 天)
显示 更早的评论
Hi all,
i have a 1x1 struct with 58 fields (1x1 double timeseries):
![Untitled.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253991/Untitled.png)
Each timeseries-field has a "Time" and "Data" column, e.g.:
![Untitled1.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253992/Untitled1.png)
So how can I now make an Excel export of the entire struct?
Unfortunately, the following just exports the field names but not the field data:
S=[test_data(:)];
writetable(struct2table(S),'test.xlsx');
Thanks.
0 个评论
回答(1 个)
Dheeraj Singh
2019-12-17
You can use the following code for implementing the above:
arr = struct2array(test_data);
t = array2table([arr.Time;arr.Data],'VariableNames',{'Time','Data'});
writetable(t,'test.xlsx');
1 个评论
DB
2021-1-18
Hi, I have tried this and got this error:
Check for missing argument or incorrect argument data type in call to function 'struct2cell'.
Error in struct2array (line 10)
c = struct2cell(s);
What do you think this means?
I have a similar dataset but with one column t, and 7 columns of data from Simulink, named out.conout:
arr = struct2array(out.conout);
t = array2table([arr.Time;arr.Data],'VariableNames',{'Time','Data'});
writetable(t,'test.xlsx');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!