Saving a .mat file in csv format

I have a .mat file and the data structure is as below.
Data =
struct with fields:
axis1: [25626600×1 double]
axis2: [25626600×1 double]
axis3: [25626600×1 double]
datenum: [25626600×1 double]
sample_rate: 30
serial_number: 'MOS2D10171145'
I want this .mat file to be save as a csv file.
I tried this code but it gives me this error.
csvwrite('FileName.csv', Data);
Undefined function 'real' for input arguments of type 'struct'.
Error in dlmwrite (line 189)
str = sprintf('%.*g%+.*gi',precn,real(m(i,j)),precn,imag(m(i,j)));
Error in csvwrite (line 42)
dlmwrite(filename, m, ',', r, c);

댓글 수: 3

mbvoyager
mbvoyager 2022년 1월 6일
편집: mbvoyager 2022년 1월 6일
csvwrite does not support to write .mat files or struct type data into a csv file. It only supports numerical matrices.
So Data is a struct consisting of several fields with different data types (vectors, scala and string?) and Data is saved in a .mat file?
Rik
Rik 2022년 1월 6일
How exactly would you like your csv file to be? Can you show an example with 10 elements (instead of the 25626600)?
Rik
Rik 2022년 1월 17일
What exactly did you edit? And how does that answer our questions?

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

답변 (1개)

Image Analyst
Image Analyst 2022년 1월 17일

0 개 추천

Try creating a double array from your structure:
data = [Data.axis1(:), Data.axis2(:), Data.axis3(:), Data.datenum(:)];
writematrix(data, fullFileName);

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

질문:

2022년 1월 6일

답변:

2022년 1월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by