Removing checkmonotonic for improving performance
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
John D'Errico
2014-1-21
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 个)
Bjorn Gustavsson
2014-1-21
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!