フィルターのクリア

Find elements in cell array (logical 0 or 1)

5 ビュー (過去 30 日間)
Cary
Cary 2015 年 8 月 15 日
コメント済み: Walter Roberson 2015 年 8 月 15 日
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 日
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!!!
Walter Roberson
Walter Roberson 2015 年 8 月 15 日
ismember(A, 'XYZ')

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by