find elements vector in a matrix

3 次查看(过去 30 天)
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

采纳的回答

Stephen23
Stephen23 2019-11-5
编辑:Stephen23 2019-11-5
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 个评论
Paul Rogers
Paul Rogers 2019-11-5
this is exactley what I was looking for.
Thanks man, you made my day!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by