How to fprintf one large variable that is a table?

5 visualizaciones (últimos 30 días)
HC
HC el 12 de Jul. de 2018
Editada: dpb el 16 de Ag. de 2021
I have a variable "fluence_rate" in my workspace that is a 24056x2000 table. How do I frpintf this and have it perfectly aligned column by column instead of one extremely long column? Also is it normal if it takes a really long time?

Respuestas (1)

dpb
dpb el 12 de Jul. de 2018
Editada: dpb el 16 de Ag. de 2021
nCol=10; % how many columns you want???
fmt=[repmat('%11.3E',1,nCol) '.\n']; % format string for that many
fprintf(fid,fmt,X.'); % print array, note transpose
Adjust the column and format to suit
  4 comentarios
djk
djk el 16 de Ag. de 2021
Thank you DB! I used your solution to print arrays with variable column numbers to a file. I found a typo, though -
fprintf(fid,X.')
should be
fprintf(fid,fmt,X.')
Thank you again.
dpb
dpb el 16 de Ag. de 2021
Editada: dpb el 16 de Ag. de 2021
Indeed, good catch...I'll fix the original to reflect.
BTW, NOTA BENE that normally the nCol would be size(x,2), the number of columns in the array itself -- but the Q? here with an array of 2000 seemed like might want to cut that down -- although if each column really were a variable, then it might still be the right thing to do, just that printing such a large array in human-readable text format is the questionable decision.

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by