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

Click For Summary
SUMMARY

The function call max(A,[],1) in MATLAB is used to compute the maximum values along the first dimension of the matrix A, which is defined as A = [2.1, 4.2, 6.7; 8.3, 5.3, 5.4]. The output mVal yields the maximum values for each column, resulting in [8.3, 5.3, 6.7], while I provides the indices of these maximum values, which are [2, 2, 1]. The empty array [] serves as a placeholder for the second argument, indicating that no specific dimension or value is being used for comparison. This syntax is part of MATLAB's flexible handling of maximum calculations across different dimensions.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with matrix operations in MATLAB
  • Knowledge of how to interpret function outputs in MATLAB
  • Basic concepts of array indexing in programming
NEXT STEPS
  • Explore MATLAB's documentation on the max function for detailed usage examples
  • Learn about multidimensional arrays in MATLAB and their manipulation
  • Investigate other MATLAB functions that operate on matrices, such as min and mean
  • Practice using MATLAB to perform various statistical operations on matrices
USEFUL FOR

Students learning MATLAB, data analysts performing matrix computations, and software developers working with numerical data in MATLAB.

gfd43tg
Gold Member
Messages
949
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: 520
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
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K