How to print an integration of double and string data?
26 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
M.R. Ebrahimi
am 11 Dez. 2020
Kommentiert: M.R. Ebrahimi
am 12 Dez. 2020
Hi
How can I print the following matrix without using table in the command window?
NONE FX NLM TV
SSIM 0.9 0.97 0.99
SNR 2 4 5
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 11 Dez. 2020
You can use fprintf() and a loop, and you get simple code.
Or you can use some fancy tricks involving putting all of the data into individual cells of a 2D cell array, and transposing the cell array so that the columns become rows,
temp = [{'SSIM'} {'SNR'}
{0.9} {2}
{0.97} {4}
{0.99} {5}]
and then
fprintf('%5s %5g %5g %5g\n', temp{:});
which would internally expand to
fprintf('%5s %5g %5g %5g\n', 'SSIM', 0.9, 0.97, 0.99, 'SNR', 2, 4, 5);
So it is possible to output mixed data with consistent formats using fprintf() in vectorized form... it just isn't pretty.
A cleaner approach is to use compose() and strjoin() the result: compose has the nice property of working row by row instead of column by column.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!