Anyone knows how to use multiple format in fprintf?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Walter Roberson
le 2 Fév 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 commentaires
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!