Clear Filters
Clear Filters

Save a matrix into text files with different names

3 views (last 30 days)
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

Answers (1)

Nihar Deodhar
Nihar Deodhar on 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

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!