how to select values of nx3 matrix where its index is equal to a value in other matrix

1 回表示 (過去 30 日間)
sana3 sal
sana3 sal 2018 年 10 月 3 日
編集済み: Stephen23 2018 年 10 月 4 日
Hi, I have two arrays the first has nx3 dimension, and the second is mx1 dimension. i need to select the first array fileds where the index of it is equal to second array value. this is what is tried so far:
[ fid, fdim]=size(f);
[ fidnew, fdimnew]=size(fnew);
for j=1:1:fid
if fid(j)==fnew(j)
FF=f;
end
end
then i have an error :
Index exceeds matrix dimensions.
Error in eee (line 26)
if fid(j)==fnew(j)
how i can solve this?
  2 件のコメント
Stephen23
Stephen23 2018 年 10 月 3 日
What is i, and how is it defined?
sana3 sal
sana3 sal 2018 年 10 月 3 日
sorry it is "j" I will edit the text

サインインしてコメントする。

回答 (2 件)

Preethi
Preethi 2018 年 10 月 4 日
hi,
try this
i=1
for j=1:1:fid
if j==fnew(j)
FF(i)=f(j)
i=i+1
end
end
since fid is a scalar fid(j) is giving error..i tired with 4x3 and 5x1 matrices, it worked

Stephen23
Stephen23 2018 年 10 月 4 日
編集済み: Stephen23 2018 年 10 月 4 日
"how to select values of nx3 matrix where its index is equal to a value in other matrix"
As far as I can tell, you can do that with basic indexing:
mat = f(fnew,:)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by