KingPolygon
KingPolygon

Reputation: 4755

Converting .mat file to .csv file results in an error?

I've looked online and have done the following to convert a .mat file into a .csv file, but I keep seeing an error. This is what I've tried:

FileData = load('mydata.mat');
csvwrite('weights.csv', FileData);

However I keep seeing the following error in matlab:

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);

Here's a bit more information about my mat file

enter image description here

Would appreciate some help!

Upvotes: 2

Views: 2728

Answers (1)

bot1131357
bot1131357

Reputation: 897

csvwrite works with matrices, not struct. You need to convert the struct into a matrix first.

Alternatively, if you're using newer versions of MATLAB and your struct members are all data arrays, you can also use T = struct2table(FileData) and then writetable(T,'myData.csv','Delimiter',',')

Upvotes: 4

Related Questions