Export Structure to csv file
古いコメントを表示
Hi everyone,
I'm trying to export my data which is saved in a structure to a csv file. The structure is two dimensional but contains vectors in some cells. So far I tried to convert it in a table and save it using writetable, but the vectors were not recorded correctly.
Thanks for any advice,
Kathrin
2 件のコメント
Turlough Hughes
2020 年 9 月 29 日
Can you attach the structure to the question?
Kathrin Sadus
2020 年 9 月 29 日
採用された回答
その他の回答 (2 件)
Sudhakar Shinde
2020 年 9 月 29 日
You can try this:
load Structure_Example.mat
writetable(struct2table(PracTrials), 'Structure_Example.csv')
The output csv file snal looks as below:

5 件のコメント
Kathrin Sadus
2020 年 9 月 29 日
Sudhakar Shinde
2020 年 9 月 29 日
Hellon Kathrin,
The multidimentional data available in structure as highlighted.

Creating a table from struct is working perfectly. This multidimentional data is now available in cell array in table.
struct2table(PracTrials)

And reaon of improper data in csv file is:
For more info:
Sudhakar Shinde
2020 年 9 月 29 日
編集済み: Sudhakar Shinde
2020 年 9 月 29 日
You could convert structure into cell array and then write cell into csv. It writes cell data perfectly in csv file.
Converting into cell array, will miss the headers. so you need to work on headers to get perfectly in csv file.
table1=struct2cell(PracTrials);
writecell( table1, 'PracTrials3.csv')
%%Alternatively try for
S=struct2table(PracTrials);
table=table2cell(S);
writecell( table, 'PracTrials2.csv')
Kathrin Sadus
2020 年 10 月 21 日
Aneesha
2021 年 12 月 3 日
can you show the format of PracTrails
Mohammad
2022 年 3 月 2 日
0 投票
Hi,
I tried to used the same method to convert my struct mat file (attached) but failed. Any help is appreciated.
カテゴリ
ヘルプ センター および File Exchange で Text Files についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!