Reputation: 9
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. I cant seem to see why it isnt working.
Note
I'm working in Matlab 2019a
Upvotes: 0
Views: 64
Reputation: 6863
You can use vectorization and the min
function.
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, :)
Upvotes: 1