MATLAB Answers

Can sections be skipped with something similar to "return" or "continue"?

조회 수: 64(최근 30일)
Steeven
Steeven 13 Apr 2018
댓글: Sean de Wolski 4 May 2020
In MatLab live scripts one can split the code into sections. This may be for a visual overview and also allows for running just a specific section at a time instead of the entire code.
I would like to ask if this sectioning is more than visual and practical but also recognizable by the code itself - can the code e.g. treat a section in the same manner as, say, a loop or a function? If so, can a section be skipped by a command similar to what commands such as return or continue do?
So, the question in short is: Is there a way to skip an entire section if a condition is met? Something like:
if ~toggle; _skip this section_; end
Skipping the rest of a function or loop is easy with e.g.:
if ~toggle; return; end
and I am looking for this similar feature for skipping a section. I am asking if this is possible before wrapping an entire section in an if-statement.

답변(1개)

Jared MacDonald
Jared MacDonald 4 May 2020
Hi Steeven,
There is currently no way to skip a section other than writing a conditional. This is an intriguing suggestion, though, and we've made a note of it.
Thanks,
Jared
  댓글 수: 4
Sean de Wolski
Sean de Wolski 4 May 2020
I agree John. And the refactor capability added a few releases ago to the live editor makes it even easier to convert something to a local or separate file function!

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by