MATLAB Answers

can I disable entire sections of code temporarily

257 ビュー (過去 30 日間)
Tom
Tom 2012 年 3 月 28 日
Commented: Miguel Ordoñez 2018 年 3 月 31 日
Can I disable entire sections of code temporarily?
I have a large code that contains different scenarios. I'm working on one scenario and I'd like to disable the other sections, just while I'm working on that bit so that I can run the code quickly without having to wait for it to do all the other stuff too.

  3 件のコメント

Matt Fig
Matt Fig 2012 年 11 月 2 日
Tom's question
Can I disable entire sections of code temporarily?
I have a large code that contains different scenarios. I'm working on one scenario and I'd like to disable the other sections, just while I'm working on that bit so that I can run the code quickly without having to wait for it to do all the other stuff too.
Giovanni Guerrero
Giovanni Guerrero 2016 年 5 月 5 日
comment out the lines using (hold) ctrl then R then undo this by (hold) ctrl then T
Kabilan Nedunchezian
Kabilan Nedunchezian 2017 年 2 月 2 日
Hi,
Use commenting in a smart way!
the following will not be executed in your code
%{
x = ('this will not be executed')
%}
to make it executable just remove the first curly bracket to make it executable
%
x = ('this will be executed')
%}

サインイン to comment.

採用された回答

kfir
kfir 2012 年 3 月 28 日
You can mark this whole part and Ctrl+R. you can also work in cell mode, and run only the cells you want.

  3 件のコメント

Tom
Tom 2012 年 3 月 28 日
Sorry, but I didn't understand that answer. I tried selecting an area of the code and pressing Ctrl+R and nothing happened. I haven't come across cell mode before.
kfir
kfir 2012 年 3 月 28 日
try looking in the "text" menu. Ctrl+R appears there.
Cell mode is a very nice tool, from Matlab 7 and above.
I also liked the answer given by Daniel. Very simple, and you can unfold all the "if" statement.
Miguel Ordoñez
Miguel Ordoñez 2018 年 3 月 31 日
Does anyone know if there is a command similar to Ctrl + R for Mac OS? Thanks

サインイン to comment.

More Answers (2)

Daniel Shub
Daniel Shub 2012 年 3 月 28 日
You can enclose code in an if block
if false
...
end
or even better (since you can include invalid syntax) would be to use block comments
%{
...
%}
The nice thing with block comments is that you can comment the comment
%%{
...
%}
to reactivate the code. The only thing to be careful with is if you auto indent and/or autowrap the code in the block comment your line breaks can get screwed up.

  0 件のコメント

サインイン to comment.


Jason Ross
Jason Ross 2012 年 3 月 28 日
Usually when I get to a place where the code has gotten this large, a little voice in my head starts screaming "PUT IT IN A FUNCTION" (or subroutine, or module, or whatever means the language I'm coding in has to compartmentalize a section of code). That way I can separate the overall program flow from the detailed bit of what each step of the program is doing. And then it becomes simple to control that flow with a comment or other conditional method.

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。

タグ

製品


Translated by