## match a categorical array in a loop

Danielle Leblance

### Danielle Leblance (view profile)

さんによって質問されました 2018 年 3 月 3 日

### Walter Roberson (view profile)

さんによって コメントされました 2018 年 3 月 8 日
Walter Roberson

### Walter Roberson (view profile)

さんの 回答が採用されました
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)?

#### 0 件のコメント

サインイン to comment.

## 1 件の回答

### Walter Roberson (view profile)

2018 年 3 月 3 日
採用された回答

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.

Peter Perkins

### Peter Perkins (view profile)

2018 年 3 月 8 日
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 (view profile)

2018 年 3 月 8 日
Good point about isequal, I missed that before.

サインイン to comment.

Translated by