问题描述
[temp,Idx] = sort(M,2 );
我想要得到每行M的排序索引,这是一个大小> 50k。
我努力搜索,但没有找到任何东西。如果您有任何意见,我们将不胜感激!
我会给你我的估计值:可能是Matlab的排序运行(在正确的向量化代码上,比如你的)和C ++一样快,而你刚刚看到运行一个采用O(n ^ 2 log n)的算法的效果。这是其排序功能比C的qsort更快,但可以带上一点盐。
I was using the built-in sort function of Matlab:
[temp, Idx] = sort(M,2);
I would like to have the sorted index of each row of M, which is a matrix of size > 50k.
I searched hard but did not find anything.. It would be greatly appreciated if you have any comments!
To get a sense of how much room for improvement you have, I would suggest writing a test program in C and use qsort or in C++ and user sort and carefully time it on 7000 inputs of size 7000 (or whatever setup you have in Matlab).
I'm going to give you my estimate: probably Matlab's sort runs (on properly vectorized code, like yours) as fast as C++, and you're just seeing the effect of running an algorithm that takes O(n^2 log n). It is reported in Matlab's marketing material that its sort function was faster than C's qsort, but take it with a grain of salt.
这篇关于如何加快Matlab中的“排序”功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!