defining a method, the purpose of the brackets
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Umut Oskay
am 12 Apr. 2020
Kommentiert: Steven Lord
am 13 Apr. 2020
while we are defining a method we write like this
function [ ] = methodsName ()
statement or statements
end
what are the purposes of [ ] and ()
Can you help me? Thanks.
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 12 Apr. 2020
In the brackets, you list all the output variables that you want your function to return. If it returns only one variable, then you can omit the bracket - they're required for 2 or more returned values.
The parentheses contain the input arguments. You list them separated by commas. For example
function theSum = GetSum(a, b)
theSum = a+b;
or
function [theSum, theProduct] = GetSumAndProduct(a, b)
theSum = a+b;
theProduct = a*b;
3 Kommentare
Steven Lord
am 13 Apr. 2020
The information about function input and output arguments in function definitions is on this documentation page.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!