Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab: What does the second argument in max(A,[],dim) mean?

Tags:

matlab

I was just using max function on a specific column of a matrix and the syntax got me wondering:

What does this empty matrix passed as the second argument mean?

max(A,[],dim)

I know it's probably for separating it from max(A,i) which does the comparison. But, why an empty matrix?

Does it have a certain meaning? Is this kind of argument used in other functions like this?

like image 814
Mahm00d Avatar asked Jun 06 '13 06:06

Mahm00d


1 Answers

Actually, your guess is right. Since Matlab is not a strongly typed language and there is no classic function overloading technique, a function must guess of a meaning of an argument by the context. Mathworks wanted to merge both finding maximum within a single matrix and along of two arrays in a single function.

Thus they need to separate these cases somehow. And they use an empty matrix [] as a placeholder. Otherwise, they won't be able to separate cases max(A, dim) and max(A, B). They could have used any special variable for this purpose, but [] is the fundamental construction.

like image 132
Mikhail Avatar answered Oct 23 '22 10:10

Mikhail