Fill a line with tabs until specified length is reached
Ältere Kommentare anzeigen
In order to format my output of multiple lines, I currently use something like
fprintf('Foo Method: \t\t\t\t\t %f',a)
fprintf('Foo et al Method: \t\t\t\t %f',b)
fprintf('Foo Method with adaptively chosen parameter:\t %f',c)
to align results.
Is there something like
fprintf('Foo Method: \t[50] %f',a)
fprintf('Foo et al Method: \t[50] %f',b)
fprintf('Foo Method with adaptively chosen parameter:\t[50] %f',c)
where \t[50] jumps to the first tab stopp that occurs at or after the 50th character of the line?
Similarly/alternatively, can I fill up a line until the 50-th character without counting myself how many characters have already been written to the line?
Akzeptierte Antwort
Weitere Antworten (1)
goerk
am 21 Jan. 2016
I think an easy way is to write your own function for this.
function str = myStr(InputStr,len)
str=InputStr;
lenDiff = len - length(str);
if lenDiff < 0
warning('String too long');
else
str = [str blanks(lenDiff)];
end
end
now you can use it:
fprintf([myStr('Foo Method:',50) '%f'],a)
1 Kommentar
Bananach
am 21 Jan. 2016
Kategorien
Mehr zu Data Type Conversion finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!