For a matrix, use two indexes to separate the logic for the columns (or rows). E.g., for the column max values using a variation of what you already have:
[nr nc] = size(a); % number of rows & columns
mxc = zeros(1,nc); % initialize a max column vector
for c=1:nc % loop over the columns
mxc(c) = a(1,c); % initial max value
for r=2:nr
% put code here for testing & updating the max value
end
end
Then adjust the above for min of columns, max of rows, and min of rows.
Best Answer