Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

matlab - Matlab,我需要找到其元素的总和最小的行(matlabr2019a)(Matlab, I need to find the row with the smallest sum of its elements (matlabr2019a))

  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 is the matrix i need to find which row has the smallest square root of its added values, I the output gives me fbest= inf and nothing for xbest.

(E是矩阵,我需要找出哪一行具有其相加值的最小平方根,我的输出是fbest = inf而xbest没有。)

I cant seem to see why it isnt working.

(我似乎看不到为什么它不起作用。)

  ask by Jhon Macieira translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use vectorization and the min function.

(您可以使用向量化和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, :) 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...