- If A is a vector, then min(A) returns the minimum of A.
- If A is a matrix, then min(A) is a row vector containing the minimum value of each column.
- If A is a multidimensional array, then min(A) operates along the first array dimension whose size does not equal 1, treating the elements as vectors. The size of this dimension becomes 1 while the sizes of all other dimensions remain the same. If A is an empty array with first dimension 0, then min(A) returns an empty array with the same size as A.
What does ''all'' mean in M = min(A, . ''all'') ?
29 views (last 30 days)
M = min(A, . ''all'')
A is a 4x4 matrix, may I know what does ''all'' means in this command?
I tried it once on Matlab, it returns the smalllest value of the matrix but it does not work in the calculation I am working on.
In fact, min(min(A)) leads to the answer I want, which is the smallest element. So what does ''all'' means in this case?
Sriram Tadavarty on 31 Jul 2020
The 'all' flag indicates all the elements of the matrix.
If the matrix A, as you mentioned is 4 x 4, then min(A,,'all') returns the minimum value of all the elements in the matrix. Implies for A, it returns the minimum of 16 elements.
The second case of min(min(A)), does perform first the minimum of A, implies it first generates minimum based on the dimensions of A
Then the minimum of the above resultant is performed again. Implies, for A, since it is a 2-D matrix, firstly min(A) will return the row vector of minimum value of each column. Then, min of the resultant vector is provided, which will be the same as that of min of all dimensions. So, for a vector or a matrix, both the syntaxes are same. Your example of A, should provide the same results.
A = [1 2 3 4;
5 6 7 8;
9 10 0 1;
2 3 4 6];
% Returns the minimum of all the elements, which is 0
% First performs minimum of A, implies min(A), which returns 1 3 0 1 (minimum of each column)
% Second perform minimum of [1 3 0 1], which is 0
% As seen above, both provide the same answer.
So, it should be the same for the matrix you considered, provided it is of 2 dimensions.
It is highly likely in the simulation you might have operating the min function with 'all' flag on multidimensional array.
Hope this helps.