Get the coordinates of a matrix from its flatten index?

You can use this simple algorithm: Let's say you have the matrix Aabcd (where a,b,c,d are the dimensions) and the index X. To get the first coordinate of the index X you simply divide X by b*c*d. Let it be this next matrix, having the sizes 25 and the index X=7 0 1 2 3 4 5 6 7 8 9 You first divide X by the last dimension to find the first coordinate.

X/5=1 . Then, from there you move forward and give X the value X%=5 . So you'll have X = 7%5 =2.

Now you have to search the coordinates for the remaining dimensions using the same algorithm. If you reach the last dimension , the coordinate will be the remaining X, in this case 2. So the coordinates for X=7 are 12 , which is actually the answear.

Again, for the general case, where you have a,b,c,d dimensions. I'll note with (yd) the y'th dimension. X=index (1d)=X/b*c*d X gets value X % b*c*d (2d)=X/c*d X gets value X % c*d (3d)=X/d X gets value X % d (4d)=X If you had the dimensions 225 you would get: X=9; (1d) = 9/2*5 = 0 X = 9%10 = 9 (2d) = 9/5 = 1 X = 9%5 = 4 (3d) = 4 Result: 014 is the 9th element.To get from 014 to the index 9 , you do the reverse algorithm by multiplying: X=(1d)*b*c + (2d)*c + 3d = 0 + 1*5 +4 =9.

1 Thank you very much, @Cristy! – Zag zag.. May 13 at 20:09.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions