フィルターのクリア

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 Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by