【问题标题】:Using histcountsmex instead of histcounts使用 histcountsmex 代替 histcounts
【发布时间】: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


【解决方案1】:

将 histcountsmex.p 添加到您当前的工作路径。 它位于 C:\ProgramFiles\MATLAB\R2017b\toolbox\matlab\datafun\private\histcountsmex.p

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 2021-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-19
    相关资源
    最近更新 更多