I ran this small code to get the indices for the matching values of b in matrix A. The output throws an error.
a = [1 2 3 4];
b = [2 3 4 5];
for i = 1:length(b)
c(i) = find(a == b(i));
end
% ---------------- OUTPUT --------------- %
Improper assignment with rectangular empty matrix.
Error in IndicesOfcomputedValues (line 5)
c(i) = find(a == b(i));

 採用された回答

madhan ravi
madhan ravi 2018 年 10 月 19 日
編集済み: madhan ravi 2018 年 10 月 19 日

1 投票

[idx,values] = ismember(b,a) %returns values and logical index of b in a
index=find(ismember(b,a)) returns linear index of b in a

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2018 年 10 月 19 日

編集済み:

2018 年 10 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by