Comparing the first char of a string in a cell

1 回表示 (過去 30 日間)
Shea Barrett
Shea Barrett 2018 年 11 月 27 日
コメント済み: madhan ravi 2018 年 11 月 27 日
I have two varaibles p and d
d = {'9S'};
p = {'9D'};
how can I compare just the first char
how would I compare the 9 in d to the 9 is p

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 11 月 27 日
編集済み: KALYAN ACHARJYA 2018 年 11 月 27 日
d={'9S'};
p={'9D'};
result=strncmpi(d,p,1)
if result=1, first character is same, else not same.
Example:
d={'PS'};
p={'QD'};
result=strcmp(d,p,1) %strcmp is case sensitive too
% Thanks @madhan Ravi
  5 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 11 月 27 日
d={'9S'};
>> array1=char(d)
array1 =
9S
>> array1(1)
ans =
9
>>
madhan ravi
madhan ravi 2018 年 11 月 27 日

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by