フィルターのクリア

Min between integer and empty array

8 ビュー (過去 30 日間)
VMIGRENN
VMIGRENN 2022 年 8 月 29 日
編集済み: VMIGRENN 2022 年 8 月 30 日
Hello,
I would like to find the min between two results from the find function. If nothing is found in one or both of the find functions, the min result is always the empty array.
How can i prefer the non empty array over the empty one ?
Thanks.
X = [1,2,3,4,10,11];
Y = [1,2,3,4,5];
indice = min(find(X>10,1),find(Y>10,1))
indice = 1×0 empty double row vector
% If the 5th element in X verifies the condition but no Y element does, the min result will always be the empty array from the find(Y>10,1).
  1 件のコメント
dpb
dpb 2022 年 8 月 29 日
Your test as written won't distinguish to which array the minimum belongs if it both are non-empty, however. Does that result do you any good other than to know that both must have had at least one element > 10?
What do you really need to know here for what further use to make of the result to pick an implementation.
Simply checking for any(X)>10) and any(Y)>10) with an if...else...end construct would be most straightforward.

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

採用された回答

Chunru
Chunru 2022 年 8 月 29 日
X = [1,2,3,4,10,11];
Y = [1,2,3,4,5];
indice = min([find(X>10,1),find(Y>10,1)]) % use brackets
indice = 6
  1 件のコメント
VMIGRENN
VMIGRENN 2022 年 8 月 29 日
That simple, thank you

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

その他の回答 (1 件)

Karim
Karim 2022 年 8 月 29 日
You can make this work by adding the dimension parameter to the min function, see below
X = [1,2,3,4,10,11];
Y = [1,2,3,4,5];
indice = min(find(X>10,1), find(Y>10,1), 2)
indice = 6
  1 件のコメント
VMIGRENN
VMIGRENN 2022 年 8 月 29 日
Works as well, thanks

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

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by