I don't know why the results of index1 and index2 are different.
The variable
financial_status=[1,2,3,4,5];
index1 = find(financial_status==or(1,2));
index2 = find(financial_status>=1&financial_status<=2);

2 件のコメント

dpb
dpb 2020 年 11 月 23 日
Because
>> or(1,2)
ans =
logical
1
>>
TAEKYU EOM
TAEKYU EOM 2020 年 11 月 23 日
I got it, thanks!

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

 採用された回答

dpb
dpb 2020 年 11 月 23 日

0 投票

Because
>> or(1,2)
ans =
logical
1
>>
You're apparently looking for
>> ismember(financial_status,[1,2])
ans =
1×5 logical array
1 1 0 0 0
>>
Rarely are the actual indices returned by find needed, but can be if this is one of those cases that simply using the logical addressing array isn't sufficient.

1 件のコメント

TAEKYU EOM
TAEKYU EOM 2020 年 11 月 23 日
I got it, thanks!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 11 月 23 日
編集済み: Walter Roberson 2020 年 11 月 23 日

0 投票

ismember(financial_status, 1:2)
At the moment I cannot think of any computer language that expresses a set membership test in terms of an equality test. Which computer language were you inspired by?

1 件のコメント

TAEKYU EOM
TAEKYU EOM 2020 年 11 月 23 日
I got it, thanks!

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

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2020 年 11 月 23 日

コメント済み:

2020 年 11 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by