Create txt file from each row of Matrix

조회 수: 1 (최근 30일)
Rounak Saha Niloy
Rounak Saha Niloy 2022년 3월 15일
답변: Rounak Saha Niloy 2022년 3월 15일
I have a matrix D with size 3x7500. I want to generate separate text files with each row of matrix. How do I do this?

채택된 답변

Rounak Saha Niloy
Rounak Saha Niloy 2022년 3월 15일
The following code worked fine for me.
A=D';
for i = 1:7500
fid = fopen([num2str(i),'.txt'],'w') ;
fprintf(fid,'%f\n',A(i,:)) ;
fclose(fid) ;
end

추가 답변 (2개)

KSSV
KSSV 2022년 3월 15일
A = rand(3,10) ;
for i = 1:3
fid = fopen([num2str(i),'.txt'],'w') ;
fprintf(fid,'%f\n',A(i,:)) ;
fclose(fid) ;
end

Arif Hoq
Arif Hoq 2022년 3월 15일
A=randi(100,3,7500);
writematrix(A(1,:),'myfile1.txt')
writematrix(A(2,:),'myfile2.txt')
writematrix(A(3,:),'myfile3.txt')

카테고리

Help CenterFile Exchange에서 Language Support에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by