84.6k views
5 votes
When the second argument isn't empty ( [ ] ), the function does an element by element comparison between the corresponding first and second arguments. Given the MATLAB variable: C = [ 6, 10, 8; 11, 13,4 ] Which of the answers below both give the same results?

A) max(C)
B) max(C, [], 1)
C) max(C, [], 2)
D) max(C, [ ], 1)

1 Answer

5 votes

Final answer:

Both A) max(C) and D) max(C, [], 1) give the same result by performing a column-wise maximum search on the matrix C, which is the default behavior of the max function in MATLAB.

Step-by-step explanation:

The MATLAB function max is used to find the maximum elements in an array. When you provide a second argument as empty brackets ([]), it indicates that MATLAB should use the default comparison behavior for the function. The default behavior without specifying a dimension for max is to return the maximum of each column when the input is a matrix, which corresponds to taking the maximum along the first dimension.

Given the variable C defined as a 2x3 matrix, the commands A) max(C) and D) max(C, [], 1) both perform a column-wise maximum search. The second command explicitly states that the maximum should be taken along the first dimension, but because this is the default behavior, both A and D will produce the same result. Option B) max(C, [], 2) calculates the maximum along the second dimension, which is row-wise, and therefore it gives a different result.

User Allen Kim
by
8.2k points