if-else function statement problem

Hello everone,
I'm trying to write a function by using the if-else function. The function searches whether the entered days are working days or not. When it comes to the first if statement in the function, it gives an error if it is not equal to it. If it is equal to the first statement, it does not give an error. What is the reason of this?
For example, when we input the following function as 'monday', it does not give an error, but when we enter the input as 'saturday', it gives an error like this. "Error in abc(line 2) if method == 'standard sampler' " How can i fix it?
function abc(day)
if day=='monday'
disp('1');
elseif day== 'saturday'
disp('2');
else
disp('bla bla');
end
end

 Respuesta aceptada

VBBV
VBBV el 2 de Dic. de 2021
Editada: VBBV el 2 de Dic. de 2021
function abc(day)
if day=='monday' % Do a comparison
disp('1');
elseif day=='saturday' % Do a comparison
disp('2');
else
disp('bla bla');
end
end

3 comentarios

Cem Eren Aslan
Cem Eren Aslan el 2 de Dic. de 2021
Editada: Cem Eren Aslan el 2 de Dic. de 2021
yes, you are right. i forgot some comma and equal sign in the question but my matlab code is the same as yours but same problem occurs.
VBBV
VBBV el 2 de Dic. de 2021
Editada: VBBV el 2 de Dic. de 2021
function abc(day)
if strcmp(day,'monday') % Do a comparison
disp('1');
elseif strcmp(day,'saturday') % Do a comparison
disp('2');
else
disp('bla bla');
end
end
"but my matlab code is the same as yours but same problem occurs" can you share the problem/error from command window everything in red text, btw, you can try also above approach
Cem Eren Aslan
Cem Eren Aslan el 2 de Dic. de 2021
thanks, problem solved

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre App Building en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 2 de Dic. de 2021

Comentada:

el 2 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by