フィルターのクリア

How to print an integration of double and string data?

15 ビュー (過去 30 日間)
M.R. Ebrahimi
M.R. Ebrahimi 2020 年 12 月 11 日
コメント済み: M.R. Ebrahimi 2020 年 12 月 12 日
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

採用された回答

Walter Roberson
Walter Roberson 2020 年 12 月 11 日
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.

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by