how to compare a string variable with a string?

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 18 Jun. 2014

0 Stimmen

Read about strcmp

1 Kommentar

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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

SRI
SRI am 18 Jun. 2014

0 Stimmen

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 Kommentar

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.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 18 Jun. 2014

Kommentiert:

am 18 Jun. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by