Filter löschen
Filter löschen

Using fprintf to export to .txt file as vertical columns

6 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 1 Jul. 2016
fmt = '%s %.2f \r\n';
data_to_write = [A(:), num2cell(B(:))] .' ; %transpose is important!
fprintf(fmt, data_to_write{:});
  6 Kommentare
Walter Roberson
Walter Roberson am 1 Jul. 2016
fprintf(fid, fmt, data_to_write{:});

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by