How to - "sort" using mexCallMATLAB ?
Show older comments
Dear all,
I am writing a mex-function and need to sort some data using the mexCallMATLAB API so that I get the data in the required form. i.e I need the data in descending order along with the index values.
In matlab - [y,i] = sort(x,1,'descend'); does the job for me. Can I simulate the same through the mexCallMATLAB API? If yes, how does it fit in the syntax for the API?
or
Should I write a C-code for the same?
Thanks in advance
Accepted Answer
More Answers (1)
Kaustubha Govind
on 1 Nov 2011
0 votes
Yes, you should be able to call into the MATLAB 'sort' implementation using mexCallMATLAB. Whether or not to implement your own algorithm in C is subjective. There is potential for performance improvement in some cases because MATLAB functions are interpreted and there is overhead for data marshaling, but it appears that the MATLAB sort is multithreaded, so you might not be able to do any faster than MATLAB can, unless you plan to call into some highly-optimized libraries. If performance is very important to you, perhaps you should perform some benchmarking to see if the MATLAB implementation is good enough for your application.
Categories
Find more on Shifting and Sorting Matrices 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!