Hi, I have this code which I am using to find index of variable a from an array b
a = 2;
b =[ 1 2 3 4 5 6 7 8 9 10];
for i = 1:1:size(b,2)
if (find (a == b))
[~,zq(i)] = (min(b(i)- a));
end
end
The problem is the result "zq", in which I am getting all ones, so I donot know the position, where a is being matched.
Does any one know?

2 件のコメント

Alex Sune
Alex Sune 2020 年 2 月 26 日
You are obtaining all ones because "b(i)- a" is scalar and the minimum value of a scalar is allways itself.
madhan ravi
madhan ravi 2020 年 2 月 26 日
Second Alex.

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

 採用された回答

Bhaskar R
Bhaskar R 2020 年 2 月 26 日

2 投票

zq = find(b == a)

2 件のコメント

madhan ravi
madhan ravi 2020 年 2 月 26 日
+1
Chris Dan
Chris Dan 2020 年 2 月 26 日
Thanks (Y)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

質問済み:

2020 年 2 月 26 日

コメント済み:

2020 年 2 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by