sub2ind_mex
This function operates in the same manner as the 'sub2ind' method. However, this method is quite faster. It is very similar to the sub2ind.m code.
Example :
>> a = [ 50 50 50 ];
>> b = [ 1 30 49 ];
>> x = sub2ind(a,b,b,b)
x =
1 73980 122449
>> xx = sub2ind_mex(a,b,b,b)
xx =
1 73980 122449
I would like to acknowledge "Marco" from the following thread. He began this bit of code a while ago and posted it here. I have simply taken it and improved its performance a bit. Thank you Marco, I do hope you don't mind what I have done here.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/262036
Update :::
I had unfortunately made a pretty big error in the code. The first while loop did not have sound logic as it was counting backwards. This would work for symmetric arrays only.
My apologies everyone!
Cite As
Christopher Harris (2023). sub2ind_mex (https://www.mathworks.com/matlabcentral/fileexchange/49165-sub2ind_mex), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.