필터 지우기
필터 지우기

writetable or dlmwrite to save an array as a txt file

조회 수: 1 (최근 30일)
Simon Lind
Simon Lind 2024년 2월 21일
댓글: Voss 2024년 4월 12일
Hello community
I need to save a txt file like this one
1 -26.2 -31.7
2 -27.1 -33.9
3 -25.5 -30.2
4 -24.4 -30.8
starting from this array
1.0000 -26.2000 -31.7000
2.0000 -27.1000 -33.9000
3.0000 -25.5000 -30.2000
4.0000 -24.4000 -30.8000
writetable seems to have limitations. Is there any other way?
Thank you!

채택된 답변

Voss
Voss 2024년 2월 21일
Here's one way:
M = [
1.0000 -26.2000 -31.7000
2.0000 -27.1000 -33.9000
3.0000 -25.5000 -30.2000
4.0000 -24.4000 -30.8000
];
filename = 'your_file.txt';
% write the file:
fid = fopen(filename,'w');
fprintf(fid,'%2d %.1f %.1f\n',M.');
fclose(fid);
% check the result:
type(filename)
1 -26.2 -31.7 2 -27.1 -33.9 3 -25.5 -30.2 4 -24.4 -30.8

추가 답변 (2개)

Walter Roberson
Walter Roberson 2024년 2월 21일
M = [
1.0000 -26.2000 -31.7000
2.0000 -27.1000 -33.9000
3.0000 -25.5000 -30.2000
4.0000 -24.4000 -30.8000
];
writematrix(M, 'your_file.txt', 'delimiter', ' ');
type your_file.txt
1 -26.2 -31.7 2 -27.1 -33.9 3 -25.5 -30.2 4 -24.4 -30.8

Simon Lind
Simon Lind 2024년 4월 12일
thank you very much for you help!

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by