Find elements in cell array (logical 0 or 1)

I have a cell column vector of stock symbols that are all three letters long. I need to create a column vector of the same length that returns a 1 when the symbol XYZ is present, and 0 when it is not. I have wasted 2+ hours trying to figure this out, it is very frustrating.
For example, if I have this:
XYZ
DHU
EYU
XYZ
XYZ
then I need a column vector like this:
1
0
0
1
1
I appreciate the help. Have a great weekend.

답변 (1개)

Stephen23
Stephen23 2015년 8월 15일
편집: Stephen23 2015년 8월 15일

0 개 추천

Use strcmp like this:
>> A = {'XYZ';'DHU';'EYU';'XYZ';'XYZ'}
A =
'XYZ'
'DHU'
'EYU'
'XYZ'
'XYZ'
>> strcmp('XYZ',A)
ans =
1
0
0
1
1

댓글 수: 2

Cary
Cary 2015년 8월 15일
Thank you!!!
ismember(A, 'XYZ')

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

카테고리

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

제품

태그

질문:

2015년 8월 15일

댓글:

2015년 8월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by