필터 지우기
필터 지우기

Save a matrix into text files with different names

조회 수: 3 (최근 30일)
Peyman Ayoubi
Peyman Ayoubi 2017년 1월 9일
답변: Nihar Deodhar 2017년 1월 9일
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

답변 (1개)

Nihar Deodhar
Nihar Deodhar 2017년 1월 9일
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

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by