Removing checkmonotonic for improving performance

1 view (last 30 days)
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

Accepted Answer

John D'Errico
John D'Errico on 21 Jan 2014
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.
  1 Comment
alessandro
alessandro on 21 Jan 2014
Hi John,
thanks for your reply. Indeed I have posted this question because I do not know what checkmonotonic actually does to my vectors, basically because I got stuck a lot of times when trying to understand how those vectors are handled into the codes, especially when dealing with plotting. For such reasons I am interested (if possible) to get an answer from technical support, even if I could create my own code for interpolation.
By the way, I would change the code only for this particular application, and would never update the function, as I know what are consequences.
Best,
Alessandro

Sign in to comment.

More Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 21 Jan 2014
Alessandro, have a look at the file exchange for the interpolation submissions, maybe some of those suits your needs. On the other hand, maybe your application is simple enough for blunt hard-coding, if so that might be fastest this time - if you dont need any bells and whistles...
HTH

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!