- 如果A是一个向量,然后最小(A)returns the minimum ofA.
- 如果A是矩阵,然后最小(A)是包含每列的最小值的行矢量。
- 如果A是一个多维数组,然后最小(A)operates along the first array dimension whose size does not equal1,将元素视为向量。这个维度的大小变成1尽管所有其他维度的尺寸保持不变。如果A是一个空数阵列,具有第一维0, then最小(A)返回一个空rray with the same size asA.
“ all”在m = min(a,[]。'all'')中是什么意思?
25 views (last 30 days)
Show older comments
M = min(A, []. ''all'')
A is a 4x4 matrix, may I know what does ''all'' means in this command?
我在MATLAB上尝试过一次,它返回矩阵的最小值,但在我正在处理的计算中不起作用。
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 Comments
Accepted Answer
Sriram Tadavarty
on 31 Jul 2020
Hi xxtan1,
“全”标志指示矩阵的所有元素。
如果您提到的矩阵A为4 x 4,则最小(a,[],'all')返回矩阵中所有元素的最小值。暗示A,它返回至少16个元素。
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)
%秒执行最小的[1 3 0 1],即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.
希望这可以帮助。
问候,
Sriram
更多的Answers (1)
Vladimir Sovkov
on 31 Jul 2020
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 Comments
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
开始狩猎!