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)
0 个评论
采纳的回答
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
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 Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!