I'm pretty new at Matlab, but I'm looking at a function that starts out like this:
function [res] = process(input)
Inside the function they define res, do some stuff with the fields in input, and put the results of those things in res. I'm wondering what could be the reason for using the [ ] in the function declaration instead of like
function res = process(input)
which I have seen much more often. Maybe if one of you can say "putting the result in an array is good because then you can ..." Thanks.
Square brackets are only required when there are multiple outputs, i.e.
function [res,other] = process(input)
If there is a single output, square brackets are optional and won't change anything, except use a little more space on your hard drive, or a little more ink when printed on paper.
My guess is that either, the function initially produced multiple outputs that got later deleted (and the square brackets were thus forgotten), or that the author likes to put square brackets for consistency with the multi-output syntax.
Think the situation with multiple outputs, there is no one single matrix created.
Basically thats just the proper Matlab syntax. More details here.
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