Create txt file from each row of Matrix

1 次查看(过去 30 天)
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