How can i show the multiplication table in the command window without showing the zeros?
조회 수: 2 (최근 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에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!