Mostra commenti meno recenti
what does () mean in the line below?
x=somefunction()
Risposta accettata
Più risposte (2)
Wayne King
il 7 Nov 2011
0 voti
The way you've written it, it implies that you are calling a function called somefunction that returns an output x. Inside the parentheses is where you supply any input arguments, name-value pairs, etc.
1 Commento
Baba
il 7 Nov 2011
Walter Roberson
il 7 Nov 2011
Then it is a function call with no parameters supplied.
Ordinary MATLAB functions that do not need a parameter, can be called either with the () notation or just by giving the function name. For example,
x = pi + rand;
is equivalent to
x = pi() + rand();
as "pi" and "rand" are both functions in MATLAB.
However, if somefunction were a function handle, then
x = somefunction;
would not call the function: instead it would copy the function handle. But
x = somefunction();
would invoke the function whether it was a regular function or a function handle.
Categorie
Scopri di più su Function Creation in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!