繁体   English   中英

Matlab,我需要找到其元素总和最小的行

[英]Matlab, I need to find the row with the smallest sum of its elements

  E = M;
fbest = inf;
for k = 1:Rows
    if sumsqr(E(k,1:Columns)) < fbest
        fbest = sumsqr(E(k, 1:Columns));
        xbest = E(k, 1:Columns);
    end
end

E 是我需要找到哪一行具有其相加值的最小平方根的矩阵,我的输出给了我 fbest= inf 而没有给 xbest 。 我似乎不明白为什么它不起作用。

笔记

我在Matlab 2019a工作

您可以使用矢量化和min函数。

E_sumsqr = sqrt(sum(E.^2, 2)) ; % determine square root of sum of squares per row
[min_value, min_index] = min(E_sumsqr) % get the minimum value and index of the row
E_minrow = E(min_index, :) 

也许你可以试试

[val,idx] = min(sqrt(sum(E.^2,2)))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM