how to compare a string variable with a string?

조회 수: 10 (최근 30일)
pricky
pricky 2014년 6월 18일
댓글: pricky 2014년 6월 18일
Hi How to compare string variable with a string?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 6월 18일
Read about strcmp
  댓글 수: 1
pricky
pricky 2014년 6월 18일
i have used strcmp but i'm getting a 0 for same string. dirName(k1+2, :) is a variable which dynamically gets the string,now i have to compare the string obtained from dirName(k1+2, :) with the one i have mentioned. ex: if i get dirName(k1+2, :) = abc.mat (dynamically)
strcmp(dirName(k1+2, :),'abc.mat')
but output is being displayed as 0.

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

추가 답변 (1개)

SRI
SRI 2014년 6월 18일
for example
inputData = 'Example';
outputData = strcmp(inputData,'Example');
If outputData = 1 means both the data are equal if 0 means it is not equal
  댓글 수: 1
pricky
pricky 2014년 6월 18일
i have used strcmp but i'm getting a 0 for same string. dirName(k1+2, :) is a variable which dynamically gets the string,now i have to compare the string obtained from dirName(k1+2, :) with the one i have mentioned. ex: if i get dirName(k1+2, :) = abc.mat (dynamically)
strcmp(dirName(k1+2, :),'abc.mat')
but output is being displayed as 0.

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by