Help with IF/Else statement in GUI
Mostrar comentarios más antiguos
Hi guys, i am new here. :) I have a problem with IF/Else statement, but only in GUI. If i put only one if statement, like this
if s=='Add'
f=x+y;
end
It works, but when i add this:
if s=='Add'
f=x+y;
end
if s=='Substract'
f=x-y;
end
It doesn't work.Also, if i only use
if s=='Substract'
f=x-y;
end
it works.I don't have a clue why is this happening.Any idea?
Respuesta aceptada
Más respuestas (2)
jack int
el 16 de Mayo de 2017
0 votos
1 comentario
Jan
el 16 de Mayo de 2017
Then please read my answer, where I explained the problem with using the == operator:
'test' == '1234'
This replies [false, false, false, false]. In the IF command you want a scalar condition. Therefore Matlab converts the expression internally to:
if all(s=='Add') && ~isempty(s=='Add')
Now try:
'test' == '123'
You get an error message, because an elementwise comparison is not working.
jack int
el 17 de Mayo de 2017
0 votos
Categorías
Más información sobre MATLAB Report Generator en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!