What does ''all'' mean in M = min(A, []. ''all'') ?

조회 수: 12 (최근 30일)
xxtan1
xxtan1 2020년 7월 31일
댓글: Vladimir Sovkov 2020년 7월 31일
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
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
  • 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.
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
xxtan1
xxtan1 2020년 7월 31일
Thank you so much, Sriram!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Vladimir Sovkov
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
xxtan1
xxtan1 2020년 7월 31일
Thank you so much for this!
Vladimir Sovkov
Vladimir Sovkov 2020년 7월 31일
One more version totally equivalent to min(A, [], ''all'') can be min(A(:)).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by