我正在尝试将 .mat 文件转换为 csv,保留向量/变量名称。这是我正在处理的一个例子:
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]
我试过使用csvwrite('test.csv', mymat)
,但它给了我一个错误:
??? 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);
我想问题是我用结构而不是矩阵来喂 csvwrite。我可以将结构变量转换为变量到矩阵,但是我会丢失变量名。
肯定有更好的方法吗?