is it posibile in matlab, jump to others command if a=1( i dont want if a~=1)

this is opposite of 'if-end' command.i need if something happens then don't do some certain command. for example:
if a==1 don't do under command until end
commands
end
other command %that if a=1 then jump here
its not needed 'if a~=1' because there are a lot of cases that a~=1 but needs command after 'if', be run too.

 Respuesta aceptada

There is no "goto" command in MATLAB if that is what you are looking for. There should be other ways to control your code flow if you could elaborate your need.
Maybe consider "switch-case". help switch. Change the value of a below to see the effect.
a=1;
switch num2str(a)
case {'2','3'}
disp('a is 2 or 3');
case {'1','4','5'}
disp('a is 1 or 4 or 5');
otherwise
disp('a is not valid');
end

3 comentarios

thanks for replying
for example 'a' could be 1,2,3,4,5,... . its needed when a=3 doesn't do a command but when a=1,2 and a=4,5,6,... does that command. could i explain better or explain more?
if a~=3
does that command
end
See the updated answer.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by