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

28 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by