How to find location of elements in an array
2 ビュー (過去 30 日間)
古いコメントを表示
I have 2 vectors 'A' of size 41*1 and 'B' of size 14*1
vector 'B' contains selected elements from vector 'A'. how do I find the position of elements present in vector 'b' in vector 'a'?
Example: A=1:1:100
B=2:2:20
Now I want to find the position of elements of B in A.
I tried find function but it throws dimention error.
Thanks in Advance
0 件のコメント
回答 (2 件)
KALYAN ACHARJYA
2020 年 7 月 5 日
編集済み: KALYAN ACHARJYA
2020 年 7 月 5 日
idx=find(ismember(A,B))
5 件のコメント
Kanupriya Singh
2020 年 7 月 5 日
Try this-
a = [2 1 3 4 6 8]
b = [2 6 8]
idx = [];
for i = 1:length(b)
idx = [idx, find(b(i) == a)];
end
2 件のコメント
Stephen23
2020 年 7 月 5 日
Rather complex... one ismember call is much simpler (and is what most MATLAB users would do).
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!