I'm trying to convert a .mat file into csv, preserving the vector/variable names. This is one example of what I'm dealing with:
mymat =
model_id: [2217x1 double]
own_dummies: [2217x26 double]
id: [2217x1 double]
product: [2217x1 double]
const: [2217x1 double]
mpd: [2217x1 double]
air: [2217x1 double]
mpg: [2217x1 double]
trend: [2217x1 double]
space: [2217x1 double]
hpwt: [2217x1 double]
cdindex: [20x1 double]
cdid: [2217x1 double]
outshr: [2217x1 double]
firmid: [2217x1 double]
share: [2217x1 double]
price: [2217x1 double]
I've tried using csvwrite('test.csv', mymat) but it gives me an error:
??? Undefined function or method 'real' for input arguments of type 'struct'.
Error in ==> dlmwrite at 192
str = sprintf('%.*g%+.*gi',precn,real(m(i,j)),precn,imag(m(i,j)));\
Error in ==> csvwrite at 32
dlmwrite(filename, m, ',', r, c);
I guess the problem is that I'm feeding csvwrite with a struct instead of a matrix. I can convert the struct variable to variable to a matrix, but then I would loose the variable names.
Surely there is a better way?