フィルターのクリア

compare two vector with considering Nan

3 ビュー (過去 30 日間)
mingcheng nie
mingcheng nie 2022 年 12 月 12 日
回答済み: Voss 2022 年 12 月 12 日
Hi there,
Is there any simple way to do the following requirements:
If I want to compare two vectors, e.g., vector A and B. They have same length. First, if the value of any entry in A/B is greater than 1 or smaller than 0, set it into Nan. Then I want to get the maximum value between A and B, set the resultant as C. If any entry in A or B is Nan, then corresponding entry in C is Nan. Finally, I want to find the minimum one in C without considering Nan.

採用された回答

Voss
Voss 2022 年 12 月 12 日
% if the value of any entry in A/B is greater than 1
% or smaller than 0, set it into Nan:
A(A<0 | A>1) = NaN;
B(B<0 | B>1) = NaN;
% get the maximum value between A and B, set the resultant as C:
C = max(A,B);
% If any entry in A or B is Nan, then corresponding entry in C is Nan:
C(isnan(A) | isnan(B)) = NaN;
% find the minimum one in C without considering Nan:
result = min(C);

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by