Finding which array a particular element is from when comparing two arrays

1 回表示 (過去 30 日間)
Tommy
Tommy 2014 年 7 月 21 日
コメント済み: Tommy 2014 年 7 月 21 日
Hi everyone
I have a question regarding to the use of the minimum function (min()). Is there a such function that finds which element is smaller while comparing two elements from two different array (I know this can be done by using min() function), and then to find out which array is this minimum value is from.
For example, I have two arrays
a = [0 , 0 , 0 , 0.5 , 0.8 , 1];
b = [0 , 0 , 0.2 , 0.6 , 0.8 ,1.2];
Both array consisting 6 elements.
Then I used a for loop to find
for i = 1 : 1 : size(a,2)
minValue(1,i) = min(a,b);
end
Is there a way that I can find which array is the element of minValue() array is from?
For example, the third element of minValue() is taken from array 'b', is there a function to do that?
Thank you very much for your help
Tommy

採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 7 月 21 日
[out,idxarr] = min([a;b]);
  1 件のコメント
Tommy
Tommy 2014 年 7 月 21 日
Hi Andrei
Thank you very much for your help
Tommy

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by