How to reuse the same format

2 visualizaciones (últimos 30 días)
Tianyi Yu
Tianyi Yu el 23 de Nov. de 2019
Editada: Tianyi Yu el 26 de Nov. de 2019
For example, this code has nine "%7.0f" and one "%5.0f". Is there any way I can simplify this code, like "repmat('%7.0f' , 9)" , but still have the "defaults->" in the front?
fprintf('defaults-> %5.0f%7.0f%7.0f%7.0f%7.0f%7.0f%7.0f%7.0f%7.0f%7.0f\n' , header')

Respuesta aceptada

Tianyi Yu
Tianyi Yu el 23 de Nov. de 2019
OK i think i solved this problem already:
fmt = ['# defaults-> %5.0f',repmat('%7.0f',1,8),'%7.0f\n',];
fprintf(fmt,header);

Más respuestas (1)

Stijn Haenen
Stijn Haenen el 23 de Nov. de 2019
Maybe this will work:
a='%7.0f';
fprintf(strcat('defaults->',repmat(a,1,9),'\n'),header);

Categorías

Más información sobre MATLAB Coder 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