Removing checkmonotonic for improving performance

1 回表示 (過去 30 日間)
alessandro
alessandro 2014 年 1 月 21 日
回答済み: Bjorn Gustavsson 2014 年 1 月 21 日
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

採用された回答

John D'Errico
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 件のコメント
alessandro
alessandro 2014 年 1 月 21 日
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

サインインしてコメントする。

その他の回答 (1 件)

Bjorn Gustavsson
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

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by