필터 지우기
필터 지우기

Using fprintf to export to .txt file as vertical columns

조회 수: 6 (최근 30일)
Cameron Spooner
Cameron Spooner 2016년 7월 1일
댓글: Cameron Spooner 2016년 7월 2일
I am running fprintf to export two columns to a .txt file. The first column (A) is a datestring with format HH:MM:SS and the second column (B) is just numerical values showing 2 d.p. I want both of these columns to display vertically. The script I am using for this is below;
fprintf(fid, '%s %.2f \r\n', A(:), B(:));
Running this the .txt file is formatted as below with all the time values horizontal followed by the temp values however every second temp value is not displaying as 2 d.p
14:48:4314:48:4614:48:4914:48:5214:48:5514:48:58 15.95
1.601000e+01 16.21
1.588000e+01 15.67
1.561000e+01
What do I need to change to the script to get it to display like below?
14:48:43 15.95
14:48:46 16.01
14:48:49 16.21
14:48:52 15.88
14:48:55 15.88
14:48:58 15.61

채택된 답변

Walter Roberson
Walter Roberson 2016년 7월 1일
fmt = '%s %.2f \r\n';
data_to_write = [A(:), num2cell(B(:))] .' ; %transpose is important!
fprintf(fmt, data_to_write{:});
  댓글 수: 6
Walter Roberson
Walter Roberson 2016년 7월 1일
fprintf(fid, fmt, data_to_write{:});

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by