How to create a matrix of coordinates

45 ビュー (過去 30 日間)
Kenny
Kenny 2019 年 2 月 22 日
コメント済み: Kenny 2019 年 2 月 25 日
I want create a matrix like this for any input, in this example input is "3".
a = (3,1) (3,2) (3,3)
(2,1) (2,2) (2,3)
(1,1) (1,2) (1,3)
But i dont know how to do

採用された回答

Yasasvi Harish Kumar
Yasasvi Harish Kumar 2019 年 2 月 22 日
Hi,
Try something like this.
n = input('Enter value')
for i = 1:2
for j = 1:n
for k = 1:n
if i == 1
a(i,j,k) = n-j+1;
elseif i == 2
a(i,j,k) = k
end
end
end
end

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2019 年 2 月 22 日
[ii,jj] = ndgrid(n:-1:1,1:n);
out = cat(3,ii,jj);
  1 件のコメント
Kenny
Kenny 2019 年 2 月 25 日
Thank You!

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

カテゴリ

Help Center および File ExchangeElementary Math についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by