"Run Section" doesn't work as I would expect

I have the following function, with a couple of code sections defined. (I've also attached it.)
function [] = runSectionBug()
%% Code Section 1
disp('I am in Code Section 1')
disp('Put a breakpoint here (line 6). Run code to this line, then try to run Code Section 2')
%% Code Section 2
disp('I am in Code section 2. But do I also see a plot when I run this section?')
figure
plot(magic(4))
drawnow
%%
end
In prior versions of MATLAB, it was possible to do the following:
  1. Place a breakpoint just ahead of Code Section 2
  2. Run the code up to that breakpoint
  3. Use "Run Section" (with the GUI button, or command-Enter on a Mac) to execute just that section
But in 2021b, that doesn't seem to work. (I don't know when this behavior changed.)
It feels like a bug to me that this does not work, because this seems like exactly the scenario that Code Sections are tailored to. But support does not seem to agree, and suggested a work-around of highlighting the code I want to run, and using the "Evaluate Selection" functionality instead.
I'm curious if other folks are using Code Sections, are/were they using them like I did, and I guess just thoughts in general.

댓글 수: 1

Adam Danz
Adam Danz 2022년 2월 11일
I also noticed this recently. The workaround I used is to manually select the section and then run selection (F9). But that can be a lot of work if the section is long.

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

 채택된 답변

the cyclist
the cyclist 2022년 2월 24일

1 개 추천

After my initial interactions with Mathworks support, I later received confirmation that this is indeed a bug in R2021b. It will be fixed in a future release (I believe R2022a).

댓글 수: 4

tmozdzen
tmozdzen 2022년 7월 4일
In 2022b, I don't see the option to "run selection" anymore.
)-:
Adam Danz
Adam Danz 2022년 7월 5일
It's easier to just press F9 to "run selection" (after highlighting a selection).
Noah
Noah 2024년 10월 16일
Using R2024a, and it still doesn't work. That's a bummer.
the cyclist
the cyclist 2024년 10월 17일
This bug I reported here was indeed fixed in R2022a, and I run sections very regularly.
I'm not sure what you are experiencing specifially, but you might want to open a new question or support request.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Aerospace Blockset에 대해 자세히 알아보기

제품

릴리스

R2021b

태그

질문:

2022년 2월 11일

댓글:

2024년 10월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by