MATLAB使用'-ascii'格式将变量保存到文本文件

时间:2014-11-19 01:14:51

标签: matlab save ascii eigen eigenvector

我在MATLAB中有以下代码:

clear;clc;
k=load('OUTPUT_sub_1_stiffness.txt');
m=load('OUTPUT_sub_1_mass.txt');
[v_default,d_default]=eig(k,m);
v_kai=load('Eigenvector.txt');
d_kai=load('Eigenvalue.txt');
[v_qz,d_qz]=eig(k,m,'qz');
[v_chol,d_chol]=eig(k,m,'chol');
save('v_default.txt','v_default','-ascii');
save('d_default.txt','d_default','-ascii');
save('v_kai.txt','v_kai','-ascii');
save('d_kai.txt','d_kai','-ascii');
save('v_qz.txt','v_qz','-ascii');
save('d_qz.txt','d_qz','-ascii');
save('v_chol.txt','v_chol','-ascii');
save('d_chol.txt','d_chol','-ascii');

所有以v开头的变量v_qz都会正确保存为文本文件,如下所示:

enter image description here

但令我惊讶的是,所有以d开头的变量(如d_qz)都无法正确保存,如下所示:

enter image description here

我想知道是否有人知道原因。

2 个答案:

答案 0 :(得分:1)

在保存之前文件是否存在?

您正在编写的变量的格式是什么?

答案 1 :(得分:0)

我明白了:刚刚添加了这个选项'-double'并得到纠正,如下所示:

save('v_default.txt','v_default','-ascii','-double');
save('d_default.txt','d_default','-ascii','-double');
save('v_kai.txt','v_kai','-ascii','-double');
save('d_kai.txt','d_kai','-ascii','-double');
save('v_qz.txt','v_qz','-ascii','-double');
save('d_qz.txt','d_qz','-ascii','-double');
save('v_chol.txt','v_chol','-ascii','-double');
save('d_chol.txt','d_chol','-ascii','-double');