Aligning numbers with text in a table

2 ビュー (過去 30 日間)
Aleem Andrew
Aleem Andrew 2021 年 11 月 16 日
編集済み: Jan 2021 年 11 月 16 日
In the code below, the numbers all occupy 13 characters of space. How do you align the words and numbers so each word also occupies 13 characters of space like in the example below the code?
fprintf('%.13s %.13s %.13s %.13s \n', 'a', 'yes','async','asychronous');
fprintf('%3.10f %3.10f %3.10f %3.10f', 33.12, 5.3819, 291.210, 39.2111);
a yes async asychronous
33.1200000000 5.3819000000 291.2100000000 39.2111000000

採用された回答

Jan
Jan 2021 年 11 月 16 日
編集済み: Jan 2021 年 11 月 16 日
% 13 characters and aligned to the right:
fprintf('%13s %13s %13s %13s \n', 'a', 'yes','async','asychronous');
a yes async asychronous
% 13 characters and aligned to the left:
fprintf('%-13s %-13s %-13s %-13s \n', 'a', 'yes','async','asychronous');
a yes async asychronous
fprintf('%3.10f %3.10f %3.10f %3.10f', 33.12, 5.3819, 291.210, 39.2111);
33.1200000000 5.3819000000 291.2100000000 39.2111000000
It was only the "." which is not used for the %s format.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by