What is the purpose of max(A,[],1)?

AI Thread Summary
The function max(A,[],1) in MATLAB is used to find the maximum values of each column in matrix A, where mVal represents these maximum values and I indicates their respective row indices. The empty brackets [] serve as a placeholder for the second argument, which specifies that no additional dimension is being considered for the maximum operation. The '1' indicates that the operation is performed along the first dimension, meaning column-wise. This syntax can seem arbitrary, but it is designed for flexibility in handling multidimensional arrays. Understanding this function is essential for effectively utilizing MATLAB for matrix operations.
gfd43tg
Gold Member
Messages
947
Reaction score
48

Homework Statement


Homework Equations


The Attempt at a Solution


Code:
A = [2.1, 4.2, 6.7; 8.3, 5.3, 5.4]

A =

    2.1000    4.2000    6.7000
    8.3000    5.3000    5.4000

Code:
[mVal, I] = max(A,[],1)

mVal =

    8.3000    5.3000    6.7000I =

     2     2     1
I don't understand what max(A,[],1) is doing. The mVal is a maximum values. The I is the index of those maximum values. What is the [] and 1 for?
 

Attachments

  • 2D arrays data manipulation.jpg
    2D arrays data manipulation.jpg
    22.2 KB · Views: 495
Physics news on Phys.org
I think the [] is just a placeholder for the second argument. There are 3 versions of max, with 1, 2, and 3 arguments.

Matlab syntax often gives me the feeling that somebody just made it up as they went along, rather than designing it to be logical, consistent, rational, etc.

http://www.mathworks.co.uk/help/matlab/ref/max.html
 
Back
Top