MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi
Learn moreOpportunities for recent engineering grads.
Apply TodayNew to MATLAB?
MATLAB Central > MATLAB Newsreader > how to use a vector as an index for a matrix 

Subject: how to use a vector as an index for a matrix From: mono Date: 9 Aug, 2012 13:13:16 Message: 1 of 12 
Hello all, 
Subject: how to use a vector as an index for a matrix From: dpb Date: 9 Aug, 2012 13:28:08 Message: 2 of 12 
On 8/9/2012 8:13 AM, mono wrote: 
Subject: how to use a vector as an index for a matrix From: Justin Ashmall Date: 9 Aug, 2012 13:33:19 Message: 3 of 12 
> I want to use a vector as index for a matrix. For example, t=[2,3], I want to point to the value in the matrix M at M(2,3). If I command as M(t), actually it points to M(2) and M(3). How can I use t to point to M(2,3)? 
Subject: how to use a vector as an index for a matrix From: mono Date: 9 Aug, 2012 14:00:23 Message: 4 of 12 
"Justin Ashmall" <juestanmatlabnews6h8@yahoo.co.uk> wrote in message <k00e6v$4fi$1@newscl01ah.mathworks.com>... 
Subject: how to use a vector as an index for a matrix From: dpb Date: 9 Aug, 2012 14:23:11 Message: 5 of 12 
On 8/9/2012 9:00 AM, mono wrote: 
Subject: how to use a vector as an index for a matrix From: Justin Ashmall Date: 9 Aug, 2012 14:27:16 Message: 6 of 12 
> Thanks for your reply. But I don't think it solves my problem. The thing is t is a vector, and its size is not fixed. It makes trouble to use its value inside. t can be t=[2,3], can also be t=[2,3,4]. Of course when t=[2,3], the matrix M is 2 dimensional, and when t=[2,3,4], M is 3 dimensional. You suggested to use sub2ind, however it still needs t as put. Obviously, M(sub2ind(size(M),t)) is not working. Any further suggestion? 
Subject: how to use a vector as an index for a matrix From: mono Date: 9 Aug, 2012 14:35:13 Message: 7 of 12 
"Justin Ashmall" <juestanmatlabnews6h8@yahoo.co.uk> wrote in message <k00hc4$frc$1@newscl01ah.mathworks.com>... 
Subject: how to use a vector as an index for a matrix From: Matt J Date: 9 Aug, 2012 14:39:14 Message: 8 of 12 
"mono" wrote in message <k00d1c$13u$1@newscl01ah.mathworks.com>... 
Subject: how to use a vector as an index for a matrix From: Bruno Luong Date: 9 Aug, 2012 14:42:15 Message: 9 of 12 
"mono" wrote in message <k00fpn$94r$1@newscl01ah.mathworks.com>... 
Subject: how to use a vector as an index for a matrix From: dpb Date: 9 Aug, 2012 14:45:05 Message: 10 of 12 
On 8/9/2012 9:39 AM, Matt J wrote: 
Subject: how to use a vector as an index for a matrix From: Bruno Luong Date: 9 Aug, 2012 14:51:16 Message: 11 of 12 
dpb <none@non.net> wrote in message <k00idl$ln6$1@speranza.aioe.org>... 
Subject: how to use a vector as an index for a matrix From: Justin Ashmall Date: 9 Aug, 2012 14:54:14 Message: 12 of 12 
"Matt J" wrote 
No tags are associated with this thread.
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.