find elements vector in a matrix

3 views (last 30 days)
Hi,
I have a matrix A 3x1201 and a vector B 3 elements. (A and B can change size but B will alway have the size of A row's).
B contains the indexes of the column in A I am intrested in.
First element of B is the index of the first row in a
Second elemnt of B is the index of the second row in A.
Third elemnt in B is the index of the third row in A.
How do I store in a new vector?
I Attached A and B to the post.
Thank You everybody!
In short I have to store in a new vector the elements:
A[1,1118]
A[2,1124]
A[3,1132]
B =
1118 1124 1132

Accepted Answer

Stephen23
Stephen23 on 5 Nov 2019
Edited: Stephen23 on 5 Nov 2019
Simply use sub2ind like this:
>> idx = sub2ind(size(psic_pos),1:size(psic_pos,1),loc);
>> vec = psic_pos(idx)
vec =
0.99353 1.0201 1.1786
And checking (the 2nd row):
>> psic_pos(2,1124)
ans =
1.0201
  1 Comment
Paul Rogers
Paul Rogers on 5 Nov 2019
this is exactley what I was looking for.
Thanks man, you made my day!

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays 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!