or() in categorical variable

조회 수: 2 (최근 30일)
TAEKYU EOM
TAEKYU EOM 2020년 11월 23일
댓글: TAEKYU EOM 2020년 11월 23일
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일
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일
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!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by