MATLAB: Find the minimum value in each row without using min

for loop if-else

I can't use function min And here is my code
x = rand([4,3])
for i = 4;
row = 0;
for j = 1:3
if x(i,j) >=0
row = row + x(i,j);
end
end
fprintf('The row %d is %d\n',i,row)
end
The answer displayed 'The row 4 is 2.245814e+00' What's wrong with my code? Can anyone help me out? thanks

Best Answer

Wrong in lots of ways. Rather than explain them all, just study my corrections:
x = rand([4,3])
[rows, columns] = size(x);
for row = 1 : rows;
theRowMins(row) = inf; % Set to infinity
for col = 1: columns
if x(row,col) < theRowMins(row)
theRowMins(row) = x(row,col);
end
end
fprintf('The min of row %d is %f\n',row,theRowMins(row))
end
% Print to command window:
theRowMins