Save a matrix into text files with different names

1 Ansicht (letzte 30 Tage)
Peyman Ayoubi
Peyman Ayoubi am 9 Jan. 2017
Beantwortet: Nihar Deodhar am 9 Jan. 2017
I have a big matrix. I am wondering how to separate it into different columns and save each column into a text file with a specified name? For example, if A=[1 2 3; 4 5 6; 7 8 9]
the result should be as X_1=[1;4;7], X_2=[2;5;8] and X_3=[3;6;8]
Thanks in advance

Antworten (1)

Nihar Deodhar
Nihar Deodhar am 9 Jan. 2017
The following illustration might help:
A=[1 2 3; 4 5 6; 7 8 9];
for i = 1:size(A,2)
X_i = A(:,i);
filename = sprintf('X_%d.txt', i);
save(filename,'X_i','-ascii')
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by