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
>>

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by