Jump command in MATLAB

前端 未结 4 1375
[愿得一人]
[愿得一人] 2020-12-04 01:38

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

相关标签:
4条回答
  • 2020-12-04 01:57

    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.

    0 讨论(0)
  • 2020-12-04 02:00

    There is no goto statement in MATLAB, but there are a few other commands for use with loops that may help you:

    • continue: This statement will skip the remaining commands in a for or while loop and move on to the next iteration.
    • break: This statement will terminate execution of a for or while loop.
    0 讨论(0)
  • 2020-12-04 02:21

    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
    
    0 讨论(0)
  • 2020-12-04 02:22
    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
    
    0 讨论(0)
提交回复
热议问题