views:

228

answers:

2

Is there a way to clear all persistent variables in MATLAB functions, while keeping the breakpoints in the corresponding function files?

clear all;

and

clear functions;

both kill the breakpoints.

+6  A: 

Unfortunately, clearing persistent variables also clears breakpoints, but there is a workaround.

After setting the breakpoints you want to retain, use the dbstatus function to get a structure containing those breakpoints and then save that structure to a MAT file. After clearing variables, you can then reload those variables by loading the MAT file and using dbstop. Following is an example of performing this sequence of operations:

s=dbstatus;
save('myBreakpoints.mat', 's');
clear all
load('myBreakpoints.mat');
dbstop(s);
RTBarnard
Note that until Matlab 2009b (I think), where they fixed the bug, the loaded breakpoints would not be visible in the editor - yet they were there.
Jonas
@RTBarnard thanks for that solution. Unfortunately it doesn't work in @-folder classes because the files where the breakpoints are, must be on the search path, from which @-folders are excluded.
Philipp
@Jonas my R2009b still has the bug
Philipp
@Philipp: Ah, so it was in the release notes of 2010a that I saw that the bug was fixed.
Jonas
+2  A: 

If there is data in @directories, you can still use the method that RTBarnard proposes

s=dbstatus('-completenames');
save('myBreakpoints.mat','s');
%# if you're clearing, you may as well just clear everything
%# note that if there is stuff stored inside figures (e.g. as callbacks), not all of 
%# it may be removed, so you may have to 'close all' as well
clear classes 
load('myBreakpoints.mat')
dbstop(s);

%# do some cleanup
clear s
delete('myBreakpoints.mat')
Jonas

related questions