Anyone knows how to use multiple format in fprintf?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I normally assign the format to fprintf individually e.g.,
fprintf('%3.0f %3.0f %3.0f %3.0f',[10 10 10 10]);
But what if I would like to assign the format only once like:
fprintf('4*%3.0f',[10 10 10 10]);
(it does not work this way, just for an example)
Is there any way I can do this?
Thank you
0 comentarios
Respuestas (1)
Walter Roberson
el 2 de Feb. de 2012
No. However, you can use
ncol = 4;
fmt = [repmat('%3.0f ', 1, ncol - 1), '%3.0f\n'];
fprintf(fmt, [10 10 10 10]);
Or if you really do not want the newline:
fmt = repmat('%3.0f ', 1, ncol);
fmt(end) = []; %remove trailing space
fprintf(fmt, [10 10 10 10]);
0 comentarios
Ver también
Categorías
Más información sobre Data Type Conversion 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!