Filter löschen
Filter löschen

Create n variables based on a int input

3 Ansichten (letzte 30 Tage)
Roberto Antonino Ruggeri
Roberto Antonino Ruggeri am 28 Nov. 2019
Kommentiert: Walter Roberson am 28 Nov. 2019
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!

Antworten (1)

Walter Roberson
Walter Roberson am 28 Nov. 2019
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.

Kategorien

Mehr zu Variables 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!

Translated by