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

In summary, the conversation is about the use of the max() function in Matlab, specifically with the arguments [] and 1. The max() function is used to find the maximum value in a matrix, and the [] is a placeholder for the second argument. There are three versions of the max() function, with 1, 2, and 3 arguments. The conversation also discusses the design and syntax of Matlab, which can sometimes seem arbitrary and illogical.
  • #1
gfd43tg
Gold Member
950
50

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: 471
Physics news on Phys.org
  • #2
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
 

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

What is a 2D array?

A 2D array is a data structure that stores data in a grid or matrix format, with rows and columns. It is a collection of elements of the same data type that can be accessed using two indices - one for the row and one for the column.

How do you initialize a 2D array?

To initialize a 2D array, you can use nested loops to assign values to each element in the array. Alternatively, you can use curly braces to initialize the array with specific values, such as int[][] arr = {{1, 2}, {3, 4}};

How do you access specific elements in a 2D array?

To access elements in a 2D array, you need to specify the index of the row and column of the element you want to access. For example, if you want to access the element in the second row and third column of a 2D array, you would use arr[1][2] since indices start at 0.

What are some common operations for manipulating 2D array data?

Some common operations for manipulating 2D array data include adding or removing rows and columns, sorting the array, and searching for specific elements. These operations can be achieved through various algorithms and programming techniques, such as nested loops and conditional statements.

How do you handle errors or exceptions when working with 2D arrays?

When working with 2D arrays, it is important to handle errors or exceptions that may arise. Some common errors include out-of-bounds errors or null pointer exceptions. To handle these, you can use try-catch blocks or conditional statements to check for these errors and handle them appropriately, such as displaying an error message or terminating the program.

Back
Top