Export Structure to csv file

438 views (last 30 days)
Kathrin Sadus
Kathrin Sadus on 29 Sep 2020
Answered: Mohammad on 2 Mar 2022
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 Comments
Turlough Hughes
Turlough Hughes on 29 Sep 2020
Can you attach the structure to the question?
Kathrin Sadus
Kathrin Sadus on 29 Sep 2020
Sure! It looks like this one here.

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 30 Sep 2020
MATLAB just introduced writestruct(): https://www.mathworks.com/help/matlab/ref/writestruct.html in R2020b. If you have R2020b, you can directly write the struct in a text file.

More Answers (2)

Sudhakar Shinde
Sudhakar Shinde on 29 Sep 2020
You can try this:
load Structure_Example.mat
writetable(struct2table(PracTrials), 'Structure_Example.csv')
The output csv file snal looks as below:
  5 Comments
Kathrin Sadus
Kathrin Sadus on 21 Oct 2020
Thank you very much for your help!
Aneesha
Aneesha on 3 Dec 2021
can you show the format of PracTrails

Sign in to comment.


Mohammad
Mohammad on 2 Mar 2022
Hi,
I tried to used the same method to convert my struct mat file (attached) but failed. Any help is appreciated.

Categories

Find more on Structures in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!