How to restore breakpoints in MATLAB after “clear

2019-04-03 05:44发布

问题:

I have a habit of beginning all my MATLAB scripts with clear all; close all; clc. While it has been a very useful line, as soon as it executes, it wipes out all my breakpoints. Is there a simple way to avoid that?

回答1:

I have solved this issue by creating a script that saves and reloads breakpoints. For convenience, you can even put it into a shortcut.

%# store breakpoints
tmp = dbstatus;
save('tmp.mat','tmp')

%# clear all
close all
clear classes %# clears even more than clear all
clc

%# reload breakpoints
load('tmp.mat')
dbstop(tmp)

%# clean up
clear tmp
delete('tmp.mat')


回答2:

clear all is a heavy hammer. For example, it also dumps all the parsed MATLAB code already in memory. A simple clear or one of the other options is usually a better choice and will not wipe your breakpoints.



回答3:

I had the same issue : after running my code, all breakpoints were deleted. I finally found that you could restore your last breakpoints by clicking on "Set / clear breakpoints" (F12 keypad).