使用histcountsmex而不是histcounts

问题描述 投票:1回答:1

我正在尝试优化我的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

现在,当我运行探查器时,它表示'histcounts'功能花费了34秒,但'histcountsmex'花费了14秒。

performance matlab mex data-analysis binning
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.