Reputation: 6592
I am working on a piece of code where points are plotted using the following command:
plot3(X(1:s,1),X(1:s,2),X(1:s,4),'.');
What is the best way to save the data? I tried with
save('File.txt','X(1:s,1),X(1:s,2),X(1:s,4)','.');
But I get the error 'X(1:s,1),X(1:s,2),X(1:s,4)' is not a valid variable name
Upvotes: 0
Views: 45
Reputation: 6592
As described here, this is a possible way to save data from a matrix:
A(1:s,1) = X(1:s,1);
A(1:s,2) = X(1:s,2);
A(1:s,3) = X(1:s,4);
fName = 'Omega_and_p.txt';
fid = fopen('Omega_and_p.txt','w');
if fid>=0
fprintf(fid, '%s\n')
fclose(fid)
end
dlmwrite(fName, A, '-append', 'newline', 'pc', 'delimiter','\t');
Upvotes: 1