【发布时间】:2016-08-22 11:30:03
【问题描述】:
我正在尝试优化我的 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(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
现在,当我运行分析器时,它显示 34 秒用于“histcounts”功能,但 14 秒用于“histcountsmex”。
【问题讨论】:
-
你一次可以在内存中容纳多少个这些向量?
-
每个向量的长度在10到5万个样本之间。
-
这不能回答我的问题...另外,您为什么确信瓶颈是
histcounts?请向我们展示一些代码,包括您已经尝试过的关于histcountsmex的代码。 -
@AboozarRoosta 以 Dev-iL 的问题为基础,您是否使用过任何时序分析功能(例如
profile)来查看histcounts是您的代码运行缓慢的原因? -
@rayryeng 是的。看我代码后面的解释。
标签: performance matlab mex data-analysis binning