Hi,
isequal(AgeState,StateState(i));
is returning a 0 although I can see visually that AgeState which is a categorical array matches StateState(i) at least 13 times. How can I find which rows in Agetate match StateState(i)?

 채택된 답변

Walter Roberson
Walter Roberson 2018년 3월 3일

0 개 추천

any(ismember(AgeState, StateState(i)), 2)
or
all(ismember(AgeState, StateState(i)), 2)
depending on whether "which rows in Agetate match StateState(i)" is intended to refer to there being at least one element of the row that matches, or if it is intended to refer to all elements in the row matching.

댓글 수: 2

Just to clarify, isequal is not the same thing as ==. isequal asks, "are the arrays the same?", and if StatState(i) is a scalar, then clearly the arrays are not the same.
If StateState(i) is a scalar, I think in addition to Walter's suggestion,
any(AgeState == StateState(i)), 2)
will also work.
Walter Roberson
Walter Roberson 2018년 3월 8일
Good point about isequal, I missed that before.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Categorical Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by