How to print an integration of double and string data?

8 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 11 Dec 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.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!