How can i show the multiplication table in the command window without showing the zeros?

1 回表示 (過去 30 日間)
close all; clear all; clc;
for i=1:10
for j=1:i
A(i,j)=i*j;
end
end
disp(A)

採用された回答

Star Strider
Star Strider 2015 年 9 月 14 日
編集済み: Star Strider 2015 年 9 月 14 日
Use repmat to define the format descriptor:
for i=1:10
for j=1:i
A(i,j)=i*j;
end
fprintf(1, [repmat(' %.0f', 1, j) '\n'], A(i,:))
end
1
2 4
3 6 9
4 8 12 16
I just displayed the first four lines here, but the table continues.
  1 件のコメント
Joseph Cheng
Joseph Cheng 2015 年 9 月 14 日
alternatively
close all; clear all; clc;
for i=1:10
for j=1:i
A(i,j)=i*j;
end
fprintf('%d ',A(i,1:i))
fprintf('\n')
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by