Performance 使用histcountsmex而不是histcounts
我正在尝试优化我的MATLAB代码。我的代码要求在for循环中对一百万个向量使用Performance 使用histcountsmex而不是histcounts,performance,matlab,mex,data-analysis,binning,Performance,Matlab,Mex,Data Analysis,Binning,我正在尝试优化我的MATLAB代码。我的代码要求在for循环中对一百万个向量使用histcounts函数。我想做的是直接使用histcountsmex,而不是histcounts。有人能建议怎么做吗? 这是我的职责: function th = sndmode( mh ) % this function will find the threshold % the mode of the function that is not zero [count, centers]
histcounts
函数。我想做的是直接使用histcountsmex
,而不是histcounts
。有人能建议怎么做吗?
这是我的职责:
function th = sndmode( mh )
% this function will find the threshold
% the mode of the function that is not zero
[count, centers]=histcounts(mh,sort((mh))); % find the most repeated elements
[~, indxs]=sort(count,'descend'); % sort the result
centers=centers(indxs);
if centers(1)==0 % determine the first nonzero mode
th=centers(2);
else
th=centers(1);
end
end
现在,当我运行profiler时,它显示“histcounts”函数花费了34秒,而“histcountsmex”则花费了14秒。将histcountsmex.p添加到当前工作路径中。
它位于C:\ProgramFiles\MATLAB\R2017b\toolbox\MATLAB\datafun\private\histcountsmex.p将histcountsmex.p添加到当前工作路径中。
它位于C:\ProgramFiles\MATLAB\R2017b\toolbox\MATLAB\datafun\private\histcountsmex.p一次可以在内存中容纳多少个向量?每个向量的长度在10000到50000个样本之间。这并不能回答我的问题。。。另外,为什么您确信瓶颈是
histcounts
?请向我们展示一些代码,包括您已经尝试过的关于histcountsmex
@aboozaroosta的代码。为了基于Dev-iL的问题,您是否使用了任何计时分析功能(如profile
)来查看histcounts
是您的代码速度慢的原因?@rayreng是的。看我在代码后面的解释。你一次能在内存中放入多少个向量?每个向量的长度在10000到50000个样本之间。这并不能回答我的问题。。。另外,为什么您确信瓶颈是histcounts
?请向我们展示一些代码,包括您已经尝试过的关于histcountsmex
@aboozaroosta的代码。为了基于Dev-iL的问题,您是否使用了任何计时分析功能(如profile
)来查看histcounts
是您的代码速度慢的原因?@rayreng是的。看我在代码后面的解释。