Azzera filtri
Azzera filtri

Using fprintf to export to .txt file as vertical columns

6 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by