how can jump and go another line in a m-file?

24 visualizaciones (últimos 30 días)
mohammad
mohammad el 31 de Ag. de 2011
Comentada: Gerrit Verboom el 28 de Mzo. de 2021
how can jump and go another line in a m-file. for example:
if a=b;
a=0;
else
(jump ***line)
end
----other commands
----other commands
.
.
.
***line
  1 comentario
Gerrit Verboom
Gerrit Verboom el 28 de Mzo. de 2021
Please, don't call me lazy when I want to use a kind of jump to or goto.
Regards,
Gerrit Verboom

Iniciar sesión para comentar.

Respuesta aceptada

Paulo Silva
Paulo Silva el 31 de Ag. de 2011
MATLAB doesn't allow silly GOTO type functions, make conditions and create functions, or the easy and dumb way:
if a=b;
a=0;
else
----other commands
----other commands
end
If those other commands repeat themselves often you should make a function with them and call that function whenever you need it.
  1 comentario
Satyam Nigam
Satyam Nigam el 21 de Mayo de 2020
for j=k:-1:3
binary_conv=(q(j)+q(j-1));
if(binary_conv<2)
f(g)=q(j);
g=g+1;
else
n=0;
break;
end
end
i need to use break here. now tell me an alternative??

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 31 de Ag. de 2011
There is a MATLAB File Exchange contribution to allow you to do what you are requesting.
  2 comentarios
mohammad
mohammad el 31 de Ag. de 2011
Walter thanks a lot
this is so useful my dear
Paulo Silva
Paulo Silva el 31 de Ag. de 2011
mohammad, jumping to lines of code is very lazy and does more harm than good, if you want to be a good programmer don't do it that way, learn to use functions and conditions to control the flux of your code.

Iniciar sesión para comentar.

Categorías

Más información sobre Software Development Tools 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