MATLAB: Removing checkmonotonic for improving performance

checkmonotonicinterp3?interpolationperformanceprofilespeed

Hi all,
I am trying to speed up a code I have written. I need to use interp3 to interpolate images into a 8connected neighborhood. When using profile I see 20% of time is spent calling checkmonotonic function. As far as I have understood from line comments availables it just checks whether provided grid components are monotonically increasing or not. This is part of the code where I create inputs for interp3:
[a,b,c]=meshgrid(1:2,1:2,1:2);
tmp=linspace(1,2,5);
[A,B,C]=meshgrid(tmp,tmp,tmp);
NewDxyz=interp3(a,b,c,Vxyz,A,B,C);
Here is the question: given that I am sure my input grid is fine (am I right? ), could I just remove this checking step to speed up my code?
Best,
Alessandro

Best Answer

It is such a bad idea to start modifying MATHWORKS supplied code. It is an especially bad idea if you don't understand the code well enough that you need to ask this very question!
CAN you remove that line? Yes, your particular application should survive unscathed, although having removed the offending line, it is no longer there to catch future problems of your own, so your own work will then become more difficult to debug.
Note that as soon as you upgrade your MATLAB license, that code will be restored. Furthermore, if anyone else is using your code, they will have the correct version of interp3. Also it is a poor idea to supply others with the modified code, since then they will no longer have the protections offered.
In general of course, remember that all such tools (mine included) fall under the rule: "You break it, you own it." Thus at that point, the author is no longer responsible for any problems that ever arise when you use that tool.
I would suggest that a better idea (if you don't like the supplied code) is to learn enough about the problem of interpolation that you can write your own highly streamlined tool to do the interpolation in a maximally efficient manner.
Related Question