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

21 次查看(过去 30 天)
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 个评论
Gerrit Verboom
Gerrit Verboom 2021-3-28
Please, don't call me lazy when I want to use a kind of jump to or goto.
Regards,
Gerrit Verboom

请先登录,再进行评论。

采纳的回答

Paulo Silva
Paulo Silva 2011-8-31
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 个评论
Satyam Nigam
Satyam Nigam 2020-5-21
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??

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2011-8-31
There is a MATLAB File Exchange contribution to allow you to do what you are requesting.
  2 个评论
mohammad
mohammad 2011-8-31
Walter thanks a lot
this is so useful my dear
Paulo Silva
Paulo Silva 2011-8-31
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Software Development Tools 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by