How to cause an error when calling fprintf or disp?

I have a large library of tight code that writes really annoying lines. I can't seem to find where they are, for some strange reason. So I thought that if I could make MATLAB throw an error when called, sprintfor disp, I could find them. Is there any way to do this?

I tried evalc, but all he gives is the conclusion itself, not from where it was called.

+4
source share
4 answers

dbstop in

, disp fprintf, dbstop. dbstack, , . , MATLAB. :

>> dbstop in disp
Warning: MATLAB debugger can only stop in MATLAB code files, and "libmwbuiltins>disp" is not a MATLAB code file.
         Instead, the debugger will stop at the point right before "libmwbuiltins>disp" is called. 

>> dbstop in fprintf
Warning: MATLAB debugger can only stop in MATLAB code files, and "libmwbuiltins>fprintf" is not a MATLAB code file.
         Instead, the debugger will stop at the point right before "libmwbuiltins>fprintf" is called.

!

testdbstop fprintTest:

function testdbstop
x=1;
disp(x)
fprintTest(x)
    function fprintTest(x)
        fprintf('%d\n',x);
    end
end

:

>> testdbstop
3   disp(x)
K>> dbstack
> In testdbstop at 3
K>> dbcont
     1
6           fprintf('%d\n',x);
K>> dbstack
> In testdbstop>fprintTest at 6
  In testdbstop at 4
K>> dbcont
1

: disp 3 testdbstop.m, fprintf 6 testdbstop.m testdbstop>fprintTest, 4 testdbstop.

. , dbclear (.. dbclear in disp dbclear in fprintf).

+2

. , disp workpacefunc , . , , keyboard .

function disp( varargin )
builtin('disp',varargin{:});
x=dbstack;
%it nessecary to exclude all calls which come via workspacefunc,
%otherwise it impossible to quit the debugger.
if numel(x)>2&&strcmpi(x(2).file,'workspacefunc.m')
    return;
end
keyboard;
end

, , , , . fprint

+2

, disp() ( error()), disp.m Matlab. disp() , .

Notepad ++ disp ("

+1

fprintf , fprintf.

fprintf, fprintf.m ( Matlab). :

function fprintf(varargin)
error('Error message to help find fprintf statements')

, , fprintf.

, fprintf.m . fprintf.m , matlab , Matlabs fprintf. , , :

which fprintf -all

Matlab , . :

which is fprintf -all C: \ Users \ MyName \ Documents \ MATLAB \ fprintf.m C: \ Program Files (x86) \ MATLAB \ R2009a \ toolbox \ matlab \ iofun \ @serial \ fprintf.m% serial method built-in (C: \ Program Files (x86) \ MATLAB \ R2009a \ toolbox \ matlab \ iofun \ fprintf)% Shadowed

Finding the missing semicolons that the variables create is harder because there are many different disp methods.

0
source

Source: https://habr.com/ru/post/1524520/


All Articles