フィルターのクリア

ismember and if not working

15 ビュー (過去 30 日間)
Khairul Nur
Khairul Nur 2021 年 7 月 22 日
コメント済み: Khairul Nur 2021 年 7 月 22 日
hi, basically i want to check whether the array "A" contains specific value or not (0,2 and 3), if the array lack of specific value, i would like to add into the array and do some counting. Here is my code. Not error but i didnt into the elseif condition.
The specific value are stored in array_include_exclude array.
Hope my explainantion is clear. Please help to solve this. TQIA
array_include_exclude=[0 2 3]'
array_include_only=[0 2]'
array_exclude_only=[0 3]'
A=[0 2]'
count1=0
count2=0
count3=0
if A ismember(array_include_exclude)
count1=count1+1
elseif A ismember(array_include_only)
A=[A 3]
count2=count2+1
elseif A ismember(array_exclude_only)
A=[A 2]
count3=count3+1
end

採用された回答

Simon Chan
Simon Chan 2021 年 7 月 22 日
Please refer to the usage of ismember below, so location of variable A is not correct,
On the other hand, rearrange the order otherwise the first condition always satisfy and exit the loop.
Syntax
if ismember(A,array_include_only)
A=[A; 3] % Modify to become a column matrix
count2=count2+1
elseif ismember(A,array_exclude_only)
A=[A; 2]
count3=count3+1
elseif ismember(A,array_include_exclude)
count1=count1+1
end
  1 件のコメント
Khairul Nur
Khairul Nur 2021 年 7 月 22 日
the code has some error on the array dimension and i edit it and working. Thanks Simon!
array_include_exclude=[0 2 3]
array_include_only=[0 2]
array_exclude_only=[0 3]
A=[0 2]
count1=0
count2=0
count3=0
if ismember(A,array_include_only)
A=[A 3] % Modify to become a column matrix
count2=count2+1
elseif ismember(A,array_exclude_only)
A=[A 2]
count3=count3+1
elseif ismember(A,array_include_exclude)
count1=count1+1
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by