defining a method, the purpose of the brackets

조회 수: 16 (최근 30일)
Umut Oskay
Umut Oskay 2020년 4월 12일
댓글: Steven Lord 2020년 4월 13일
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.

채택된 답변

Image Analyst
Image Analyst 2020년 4월 12일
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
Steven Lord
Steven Lord 2020년 4월 13일
The information about function input and output arguments in function definitions is on this documentation page.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by