How can I set the table parameter in .txt output

조회 수: 2 (최근 30일)
M.R. Ebrahimi
M.R. Ebrahimi 2021년 5월 9일
댓글: M.R. Ebrahimi 2021년 5월 9일
I want to wirte a txt file which its elements space will be exactly 2 space. For example:
12667 576614.0000 3723897.0000 852.0000 6.0000 1750.0000
The code i wrote is the following:
FID=fopen('Header.txt','w');
fprintf(FID,'%i %3.4f %3.4f %3.4f %3.4f %3.4f\n',Table); (Table is the 6*100 matrix I wanna to write)
fclose(FID);
My problem is that the output txt file elemnts space are 1 instead of 2 (12667 576614.0000 3723897.0000 852.0000 6.0000 1750.0000)
How can I modify the code?
Thanks

채택된 답변

Rik
Rik 2021년 5월 9일
Because you didn't tell Matlab to use 2 spaces in the FormatSpec. Compare the two versions below (the second line is to provide a scale to check for double spacing).
data=[12667 576614.0000 3723897.0000 852.0000 6.0000 1750.0000];
fprintf('%i %3.4f %3.4f %3.4f %3.4f %3.4f\n',data);fprintf('%d',mod(0:80,10))
12667 576614.0000 3723897.0000 852.0000 6.0000 1750.0000 012345678901234567890123456789012345678901234567890123456789012345678901234567890
fprintf('%i %3.4f %3.4f %3.4f %3.4f %3.4f\n',data);fprintf('%d',mod(0:80,10))
12667 576614.0000 3723897.0000 852.0000 6.0000 1750.0000 012345678901234567890123456789012345678901234567890123456789012345678901234567890

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by