I'm still convinced that the conditional breakpoints solve your problem. Set the breakpoints automatically:
And the function to set the breakpoints:
function bruteDBOnCondition(mFile, Condition)
[~, mName] = fileparts(mFile);
CStr = strsplit(fileread(mFile), '\n');
dbstop('in', mName, 'at', sprintf('%d', k), 'if', Condition)
You do not have to call bruteDBOnCondition() from inside the function to be supervised, but here it avoids to check the value of x before it is defined. Maybe this is smarter:
bruteDBOnCondition(which('dbTest'), 'exist(''x'', ''var'') && ~isequal(x, 0)');
You can do this for all subfunctions also.
You could reduce the number of breakpoints also, by selecting only lines, in which the symbol 'x' or 'x(' occurs left from a '=' character.