Borrar filtros
Borrar filtros

how to compare a string variable with a string?

10 visualizaciones (últimos 30 días)
pricky
pricky el 18 de Jun. de 2014
Comentada: pricky el 18 de Jun. de 2014
Hi How to compare string variable with a string?

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 18 de Jun. de 2014
Read about strcmp
  1 comentario
pricky
pricky el 18 de Jun. de 2014
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.

Iniciar sesión para comentar.

Más respuestas (1)

SRI
SRI el 18 de Jun. de 2014
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 comentario
pricky
pricky el 18 de Jun. de 2014
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by