Create matrix with elements representing distance from centre of matrix
Show older comments
Hello. If i have a 3x3, 5x5 or 7x7 matrix or generally a nxn matrix where n is odd, i want each element to represent the distance from the centre of the matrix. I.e the top left element in a 3x3 matrix to represent up one row and left 1 column. I.e (1,-1).
I then want to unravel this matrix into a 1D vector but in a serpentine fashion rather than raster scan
Accepted Answer
More Answers (2)
darova
on 31 Jan 2021
What about this?
m = 5;
n = (m-1)/2;
[X,Y] = meshgrid(-n:n);
A = sqrt(X.^2+Y.^2)
surf(A)

Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!