필터 지우기
필터 지우기

Create n variables based on a int input

조회 수: 3 (최근 30일)
Roberto Antonino Ruggeri
Roberto Antonino Ruggeri 2019년 11월 28일
댓글: Walter Roberson 2019년 11월 28일
Hi I've a function to generale a spline curve.
I need to repeat this function several times in order to create curve1, curve2, curve3, curve4 and so on.
How can I define only 1 function which takes as input the number of curves I want to create and returns all the variables calculated in the function as:
pointsofcurve1=[...]
curve1=[...]
pointsofcurve2=[..]
curve2=[...]
and so on..?
Last number of all the variables inside the function such as pointsofcurveX, curveX needs to be created automatically in order to generate all the variables of each curve and the curve itself.
Thank you very much!

답변 (1개)

Walter Roberson
Walter Roberson 2019년 11월 28일
You cannot. It is only possible to return as many variables as the user provided space for when they called the function.
You can use nargout to test how many return variables the user asked for.
You do not need to name the output variables individually. Instead you can use the special name varargout and treat it like a cell array. Assign to varargout{K} to assign to the Kth output variable.

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by