Search code examples
matlabsuppress-warningsoverloading

Avoid MATLAB startup warning when overloading buildin functions?


As described here, I created my own figure.m which nicely overloads the built-in figure command. Now, whenever I start MATLAB I get the warning

Warning: Function C:\somepath\figure.m has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.

Is there any way to deactivate this warning, given that it is desired behavior in my case?

You might say that I should call my function differently instead of overloading, but I do feel for my development system this overloading is the right way to go...

Update

As mentioned by Aabaz you can globally turn off this warning using

warning off MATLAB:dispatcher:nameConflict

which needs to go at the beginning of matlabrc.m (before the path is set). However, I would still be interested in a solution which could specificially remove this error message for overloading figure.m (or some self-defined list of functions) instead of for all functions. I guess I'm asking a bit too much here ;-) ?


Solution

  • I cannot seem to replicate this warning with my Matlab version (R2008b) but anyway If you did not already try it you should look into the functions lastwarn and warning that allow you to identify and turn off this warning.

    PS: the warning eventually came for some reason and I was able to use lastwarn and warning to turn it off.

    >>[msgstr msgid]=lastwarn;
    >>disp(msgid);
    MATLAB:dispatcher:nameConflict
    >>warning('off',msgid);
    

    I should add that you should turn it off at startup for this to be effective between different sessions of Matlab.