MATLAB: I have this command “min(A(:,b),[ ],2)”, where A is a matrix and b is one of its columns. How does it works

matrixminimum

Hi everyone! I have this piece in a code I am trying to understand but I don't know what does it means when "[]" and "2" are added inside the min function. Thank you for your help. 🙂

Best Answer

Hello Vio,
A = [1.7 1.2 1.5; 1.3 1.6 1.99]
M = min(A,[],2) %This gives minimum along rows
and
A = [1.7 1.2 1.5; 1.3 1.6 1.99]
M = min(A,[],1) %This gives minimum along columns
If you don't use [ ] in your code, it shows a modified matrix with all the elements of A. If any value is greater than n, then it is replaced by n otherwise it is unchanged
n=6;
A = [1.7 1.2 6.5; 1.3 1.6 6.99]
M = min(A,n);
and
n=7;
A = [1.7 1.2 6.5; 1.3 1.6 6.99]
M = min(A,n);
This is something I observed while coding. Just wanted to share. I hope it will be helpful.