How to create a matrix of coordinates

34 Ansichten (letzte 30 Tage)
Kenny
Kenny am 22 Feb. 2019
Kommentiert: Kenny am 25 Feb. 2019
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

Akzeptierte Antwort

Yasasvi Harish Kumar
Yasasvi Harish Kumar am 22 Feb. 2019
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

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 22 Feb. 2019
[ii,jj] = ndgrid(n:-1:1,1:n);
out = cat(3,ii,jj);

Kategorien

Mehr zu Elementary Math 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