I\'m working with the m-file editor of MATLAB and I need to jump from one line to another.
If I need to jump from inside a For
...end
, I can\'t use
There is no goto in matlab. However, this does not say you cannot structure your code to use an {if, else, elseif, end} structural form for your code. Or use a {switch, case, end} form. Or call a function (or subfunction or nested function) to solve your problem. Or use a continue/break to structure your code. One can always solve these problems using one of the existing forms of flow control available.
The use of functions can improve your code in other ways, often by making it more modular, and therefore easier to debug and write.
There is no goto
statement in MATLAB, but there are a few other commands for use with loops that may help you:
that solves the problem easily:
caseno = input('input your case no');
switch (caseno)
case 1
disp('this first section will run');
case 2
disp('this second section will run');
otherwise
disp('wrong case no');
end
for j = 1: 1: 24
% LABEL start
a = a + j;
if a > 10
goto('start') % If condition satisfied goto label start
return
else
a = a + 1;
end
end