MATLAB: Function [output]=F​unctionNam​e(input)

bracketsfunction

I don't understand why sometimes a pair of brackets is used when a function is created. I have seen it in two cases:
1. the output is empty 2. the output is logical
Can someone please help me to clarify the scope of using a pair of brackets for the output when a function is created?

Best Answer

Go to Create Functions in Files and look for Syntax for Function Definition. It says:
Output arguments (optional)
If your function returns one output, you can specify the output name after the function keyword. [...] If your function returns more than one output, enclose the output names in square brackets.
function [one,two,three] = myFunction(x)
The brackets are optional with zero and one output.
The Matlab template includes the brackets
function [ output_args ] = Untitled( input_args )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
end
I guess, this template encourage the use of brackets with zero and one output.
Related Question