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

3 Ansichten (letzte 30 Tage)
close all; clear all; clc;
for i=1:10
for j=1:i
A(i,j)=i*j;
end
end
disp(A)

Akzeptierte Antwort

Star Strider
Star Strider am 14 Sep. 2015
Bearbeitet: Star Strider am 14 Sep. 2015
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.

Weitere Antworten (0)

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by