find elements vector in a matrix

3 ビュー (過去 30 日間)
Paul Rogers
Paul Rogers 2019 年 11 月 5 日
コメント済み: Paul Rogers 2019 年 11 月 5 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by