or() in categorical variable

1 vue (au cours des 30 derniers jours)
TAEKYU EOM
TAEKYU EOM le 23 Nov 2020
Commenté : TAEKYU EOM le 23 Nov 2020
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 commentaires
dpb
dpb le 23 Nov 2020
Because
>> or(1,2)
ans =
logical
1
>>
TAEKYU EOM
TAEKYU EOM le 23 Nov 2020
I got it, thanks!

Connectez-vous pour commenter.

Réponse acceptée

dpb
dpb le 23 Nov 2020
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 commentaire
TAEKYU EOM
TAEKYU EOM le 23 Nov 2020
I got it, thanks!

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 23 Nov 2020
Modifié(e) : Walter Roberson le 23 Nov 2020
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 commentaire
TAEKYU EOM
TAEKYU EOM le 23 Nov 2020
I got it, thanks!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by