Effacer les filtres
Effacer les filtres

Create n variables based on a int input

3 vues (au cours des 30 derniers jours)
Roberto Antonino Ruggeri
Roberto Antonino Ruggeri le 28 Nov 2019
Commenté : Walter Roberson le 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!

Réponses (1)

Walter Roberson
Walter Roberson le 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.

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by