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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With