How to create a table by making printing new lines

1 回表示 (過去 30 日間)
NIMA RAHMANI MEHDIABADI
NIMA RAHMANI MEHDIABADI 2019 年 4 月 10 日
回答済み: Geoff Hayes 2019 年 4 月 10 日
So i am trying make a table of numbers like
0 0 0 1 2
0 0 1 2 3
0 1 2 3 4
my code is :
numbers are different so dont worry about them.
m = 5;
n = 5;
A = zeros(m,n);
for i = 1:m
for j = max(1,n-i):min(n,n+2-i)
if (i+j == 5)
A(i,j) = 2;
elseif (i+j == 6)
A(i,j) = 6;
else
A(i,j) = 4;
end
end
end
fprintf('%5d',A)
However the outcome is
0 0 0 1 2 0 0 1 2 3 0 1 2 3 4

採用された回答

Geoff Hayes
Geoff Hayes 2019 年 4 月 10 日
Nima - try doing
fprintf('%d %d %d %d %d\n',A)
instead to print out the rows of five columns.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by