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
Turlough Hughes 2020년 9월 29일
Can you attach the structure to the question?
Kathrin Sadus
Kathrin Sadus 2020년 9월 29일
Sure! It looks like this one here.

댓글을 달려면 로그인하십시오.

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 9월 30일

1 개 추천

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.

추가 답변 (2개)

Sudhakar Shinde
Sudhakar Shinde 2020년 9월 29일

1 개 추천

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
Kathrin Sadus 2020년 9월 29일
Thanks, that was exactly what I was trying, but as soon as I'm using a different structure it seems to fail to convert the table into a csv file. I attached the strcuture and the resulting file.
Again, thanks for helping!
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
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
Kathrin Sadus 2020년 10월 21일
Thank you very much for your help!
Aneesha
Aneesha 2021년 12월 3일
can you show the format of PracTrails

댓글을 달려면 로그인하십시오.

Mohammad
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.

카테고리

제품

태그

질문:

2020년 9월 29일

답변:

2022년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by