- 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'') ?
조회 수: 12 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
Sriram Tadavarty
2020년 7월 31일
Hi xxtan1,
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.
% Example:
A = [1 2 3 4;
5 6 7 8;
9 10 0 1;
2 3 4 6];
>> min(A,[],'all')
% Returns the minimum of all the elements, which is 0
>> min(min(A))
% 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.
Regards,
Sriram
추가 답변 (1개)
Vladimir Sovkov
2020년 7월 31일
All this is fairly well described in the matlab documentation. min(min(A)) and min(A, [], ''all'') are equivalent for 1D and 2D arrays but differ for bigger dimensions.
댓글 수: 3
Vladimir Sovkov
2020년 7월 31일
One more version totally equivalent to min(A, [], ''all'') can be min(A(:)).
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!