how to run only a part of code in Mac OS?
44 views (last 30 days)
Show older comments
Hi! I am new to Mac OS, and have a simple question on the function keys. When I was using Matlab on Windows, it was possible to run only some part I want in Editor just by pressing F9 key. Is it also possible in Mac OS?
0 Comments
Answers (1)
Steven Lord
on 6 Sep 2017
Yes. Select the code you want to run and right-click. The menu option "Evaluate Selection" should appear in the context menu, and next to it should be the keyboard shortcut for that option. You can customize those shortcuts if you want via the Preferences.
2 Comments
Steven Lord
on 7 Sep 2017
All the code you wrote should run only if you've selected all your code, not just a subset that you want to run when you Evaluate Selection.
Write these three lines of code in a new script file in the Editor, select JUST the middle line, right-click on that line, and select "Evaluate Selection". Does it bring up a new figure window? It shouldn't, it should just create a variable y (or overwrite the contents of y if it already exists, so if you need that variable save its contents to a MAT-file or copy it to another variable. You might want to do the same with x, just in case.)
x = 1:10;
y = (1:10).^2;
figure; plot(x, y)
There is another approach to evaluating code one section at a time that I forgot to mention in the original post, and that is cell mode.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!