Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 使用histcountsmex而不是histcounts_Performance_Matlab_Mex_Data Analysis_Binning - Fatal编程技术网

Performance 使用histcountsmex而不是histcounts

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]

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

现在,当我运行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是的。看我在代码后面的解释。