Hello!
I need to export the answer for .txt file.
Columns must have spaces between them.
2 spaces before the first column.
3 spaces between 1 e 2 columns
3 spaces between 2 e 3 columns
6 spaces between 3 e 4 columns
6 spaces between 4 e 5 columns
1 space between 5 e 6 columns
2 spaces between 6 e 7 columns
2 spaces between 7 e 8 column
2 spaces between 9 e 10 column
2 spaces between 10 e 11 column
May someone help me?
A = importdata('teste.txt')
for M = 1:length(A);
if A (M,7) == 1;
A (M,1) = 0;
A (M,2) = 0;
A (M,3) = 0.78539;
elseif A (M,7) == 2;
A (M,1) = 0;
A (M,2) = 1.57089;
A (M,3) = 0.78539;
elseif A (M,7) == 3;
A (M,1) = 1.57089;
A (M,2) = 1.57089;
A (M,3) = 0.78539;
end
end

 채택된 답변

Jan
Jan 2022년 6월 14일
편집: Jan 2022년 6월 14일

0 개 추천

M = [ 4.12449 0.37223 0.89067 0.00000 0.00000 11492.2 1.000 1 17214 0.103];
[fid, msg] = fopen('answer.txt', 'w');
assert(fid > 0, msg);
fprintf(fid, ' %.6g %.6g %.6g %f %f %.6g %.3f %d %f %.3f\n', M.');
4.12449 0.37223 0.89067 0.000000 0.000000 11492.2 1.000 1 17214.000000 0.103
fclose(fid)
The numerical format is tricky: with %f the number of digits after the dot can be fixed, with %g the number of significant digits.

추가 답변 (1개)

Ariane Moura
Ariane Moura 2022년 6월 14일

0 개 추천

Thanks a lot!!!!

카테고리

도움말 센터File Exchange에서 Standard File Formats에 대해 자세히 알아보기

제품

릴리스

R2017b

태그

질문:

2022년 6월 14일

답변:

2022년 6월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by