MATLAB: Finding minimum value of certain row of matrix with condition

minimun distance

i have matrix [6,6], how to find minimum value at certain row eg what is the minimum value that >0, at row 1?
r=[0.00 18.68 39.62 20.81 5.39 39.92
18.68 0.00 33.84 38.91 24.04 53.41
39.62 33.84 0.00 48.38 42.20 45.12
20.81 38.91 48.38 0.00 15.62 25.08
5.39 24.04 42.20 15.62 0.00 36.40
39.92 53.41 45.12 25.08 36.40 0.00];
Then the result is 5.39 in [1 5], it will loop to continued to find the min value at other row, the next row searching on the min value is based on the previous result of the column. eg 2nd result is 15.62 [5 4]

Best Answer

If I understood you correctly, try this:
clc;
workspace;
fontSize = 25;
close all;
r=[0.00 18.68 39.62 20.81 5.39 39.92
18.68 0.00 33.84 38.91 24.04 53.41
39.62 33.84 0.00 48.38 42.20 45.12
20.81 38.91 48.38 0.00 15.62 25.08
5.39 24.04 42.20 15.62 0.00 36.40
39.92 53.41 45.12 25.08 36.40 0.00];
[rows, columns] = size(r)
thisMin = -1*ones(rows, 1);
priorRowMin = 0;
for row = 1 : rows
% Get this row all by itself.
thisRow = r(row, :);
% Remove values less than or equal to the prior row's min
% because we only want to consider values above the prior row's min.
thisRow(thisRow <= priorRowMin) = [];
if ~isempty(thisRow)
% If there are any values left...
% Find the min of what's left.
thisMin(row) = min(thisRow);
% Update the prior row min:
priorRowMin = thisMin(row);
end
end
thisMin
In the command window:
thisMin =
5.39
18.68
33.84
38.91
42.2
45.12