- 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!