How can I change Indexing of a Matrix?

44 views (last 30 days)
I want to change the index values of my matrix .
A = [ 1 3 4 5 7
2 2 1 1 8
3 8 1 2 5
9 7 4 3 3
1 9 3 0 2]
now if i run A(3,3) my answer will be 1,
A(1,1) my answer will be 1 and so on..
but i want to change the indexes of my matrix , such if i type A(0,0) i should get 1 ( A(0,0) should replace A(3,3)
similarly A(-2,-2) = 1 (A(-2,-2) should replace A(1,1).
How to change the indexes of the matrix such that the center is 0,0 . ?

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 8 Dec 2020
This seems like a "very ambitious idea, with dubious benefits". But I'm not the one to judge, so I'll guess you have some good reasone for doing this, it might help you to get good advice if you clarified those reasons.
Meanwhile you might get something out of this file exchange submission (that offers zero-based indexing, so you will have to do some modification of the code to give it "centre-based indexing"): zero-based-indexable-arrays-oop.
HTH
  5 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 8 Dec 2020
If I've understood the fundamental mathematics to any degree there will be an infinite number of points along any line-segment through a circle.
That's not the answer to your question, but you have to think about what the question requires. One first step is to do each part you can easily figure out how to do separately, do them separately, then have a think about how to combine these steps and what modifications you need to do to get that done.
Also: there's nothing wrong with using meshgrid.
Finally: Creating a "centred-based" matrix is not at all relevant to this question.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!