Comparing the first char of a string in a cell

1 Ansicht (letzte 30 Tage)
Shea Barrett
Shea Barrett am 27 Nov. 2018
Kommentiert: madhan ravi am 27 Nov. 2018
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

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 27 Nov. 2018
Bearbeitet: KALYAN ACHARJYA am 27 Nov. 2018
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 Kommentare
KALYAN ACHARJYA
KALYAN ACHARJYA am 27 Nov. 2018
d={'9S'};
>> array1=char(d)
array1 =
9S
>> array1(1)
ans =
9
>>

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by