Bruno Luong (2021). find_idx (https://www.mathworks.com/matlabcentral/fileexchange/23049-find_idx), MATLAB Central File Exchange. Retrieved .
Thanks for your comment. Fair enough. histc is fater than interp1. I also discovered this fact recently (after I developed this code and benchmark various methods in fact), and this is something I did not expected.
This would be useful to anyone implementing an interpolant in one dimension, or for those writing an interpolation in higher dimensions on a regular lattice. For example, a tensor product interpolant would benefit from this code as the first step, as would some other methods.
I won't offer a rating since I cannot test this without a c-compiler, and without the presence of the compiled version, it just calls interp1 as the engine. It looks well done to me from a quick read through of the code though. I won't make any claim about the c code, since I have no skills in that respect.
I'm not sure about the speed claim though, since if the author has based the claim of speed to a comparison to interp1, I can achieve a 55% reduction in time over interp1 just by a simple call to histc.
xgrid = (0:.1:10);
xi = rand(1,10000)*10;
Elapsed time is 0.010040 seconds.
tic,B = interp1(xgrid,(1:length(xgrid)), xi);toc
Elapsed time is 0.022428 seconds.
Both code fragments generate the same outputs, yet the histc one is considerably faster, and written in basic matlab. Any comparison of time should use this as the reference, not interp1.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!