http://www.mathworks.com/matlabcentral/newsreader/view_thread/286662
MATLAB Central Newsreader  Selecting values in matrix based on index
Feed for thread: Selecting values in matrix based on index
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Mon, 12 Jul 2010 11:47:05 +0000
Selecting values in matrix based on index
http://www.mathworks.com/matlabcentral/newsreader/view_thread/286662#761776
Ulrik Nash
Hi Everyone,<br>
<br>
I thought I had this one nailed, but I can't seem to get what i want:<br>
<br>
Suppose I have a matrix A:<br>
<br>
A = [1 5; 2 3; 4 4]<br>
<br>
and B<br>
<br>
B = [1 3]<br>
<br>
Now, I want to select the values in A given by the index in B, but in column 2, not column 1<br>
<br>
If I use the command:<br>
<br>
C = A(B)<br>
<br>
I get the correct rows, but not the correct column.<br>
<br>
What am I missing?<br>
<br>
Kind regards,<br>
<br>
Ulrik.<br>
<br>

Mon, 12 Jul 2010 12:04:05 +0000
Re: Selecting values in matrix based on index
http://www.mathworks.com/matlabcentral/newsreader/view_thread/286662#761781
Ulrik Nash
"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <i1evbp$lmv$1@fred.mathworks.com>...<br>
> Hi Everyone,<br>
> <br>
> I thought I had this one nailed, but I can't seem to get what i want:<br>
> <br>
> Suppose I have a matrix A:<br>
> <br>
> A = [1 5; 2 3; 4 4]<br>
> <br>
> and B<br>
> <br>
> B = [1 3]<br>
> <br>
> Now, I want to select the values in A given by the index in B, but in column 2, not column 1<br>
> <br>
> If I use the command:<br>
> <br>
> C = A(B)<br>
> <br>
> I get the correct rows, but not the correct column.<br>
> <br>
> What am I missing?<br>
> <br>
> Kind regards,<br>
> <br>
> Ulrik.<br>
> <br>
Sorry, to waste time. I got it:<br>
<br>
C = A(B,2)<br>
<br>
Correct me if I am wrong...