Effacer les filtres
Effacer les filtres

How to print an integration of double and string data?

15 vues (au cours des 30 derniers jours)
M.R. Ebrahimi
M.R. Ebrahimi le 11 Déc 2020
Commenté : M.R. Ebrahimi le 12 Déc 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

Réponse acceptée

Walter Roberson
Walter Roberson le 11 Déc 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.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by