having problem to call m.file

please assist the below. exparx showing results = 0
exparx='expfun1cf1';
if exparx == 'expfun1cfd';
....
elseif exparx == 'expfun1cf1';
...
end

Respuestas (2)

Walter Roberson
Walter Roberson el 15 de Ag. de 2016

0 votos

Use strcmp() to compare strings.
Thorsten
Thorsten el 15 de Ag. de 2016

0 votos

You can use switch to compare a string variable to different other constant strings:
switch exparx
case 'expfun1cfd'
% do some stuff
case 'expfun1cf1'
% do some other stuff
end

1 comentario

Guillaume
Guillaume el 15 de Ag. de 2016
You can use switch to compare a string ...
... which uses strcmp to do the comparison. As per Walter's answer, string comparison must be done with strcmp, never with ==.
If you want to have several branches depending on the value of the string, then indeed using switch as per Thorsten's answer may be more elegant than several if strcmp ... else if strcmp ...

La pregunta está cerrada.

Etiquetas

Preguntada:

el 15 de Ag. de 2016

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by