how to combine matrix column and saving them as a separate text file?

조회 수: 1 (최근 30일)
Hydro
Hydro 2017년 6월 20일
답변: Jan 2017년 6월 20일
suppose i have two large matrices of the same size (10950*45) and i would like to combine each corresponding column of the two matrices into a separate text file with naming as file1, file2.....file45. below is just an example what i wanted to achieve.
A=randi(1000,100);
B=randi(1000,100)*5;
file1=[col1_A Col1_B]; file2=[col2_A Col2_B];file3=[col3_A Col3_B].....file100=[col100_A Col100_B]
Thanks in advance

답변 (1개)

Jan
Jan 2017년 6월 20일
A = randi(1000,100);
B = randi(1000,100)*5;
for k = 1:100
Data = [A(:, k), B(:, k)];
FileName = sprintf('file%d.txt');
... do what you want with the data and the file name
end
You did not specify how the "file1" etc should be created. Avoid to create large text files, because binary files are much more efficient. Text files are useful only, if human should read and edit them - or if another programmer forgot this important detail.

카테고리

Help CenterFile Exchange에서 Other Formats에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by