MATLAB save variables to text files with '-ascii' format

4.2k views Asked by At

I have the following code in 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');

All the variable which start with v like v_qz are saved correctly as text files as shown below:

enter image description here

However, to my surprise, all the variable which start with d like d_qz can not be saved correctly, as shown below:

enter image description here

I wonder if anybody knows why.

2

There are 2 answers

0
Megidd On BEST ANSWER

I figured it out: just added this option '-double' and it got corrected, like below:

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');
1
James On

Do the files exist before you save them?

And what is the format of the variable you are writing?