converting a multiple input function to a vector input function

6 vues (au cours des 30 derniers jours)
Trevor
Trevor le 17 Juin 2015
Commenté : Walter Roberson le 18 Juin 2015
My question is similar to this one
I have a vector of symbolic expressions called "xdot_sym". Following the advice of the thread above I convert this function to a vector input function by the following
xdot_fun = matlabFunction(xdot_sym);
xdot_fun_vec = @(x) xdot_fun(x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10),x(11),x(12));
This works fine. However the length of my vector xdot_sym often changes. So I am looking for a way to define xdot_fun_vec for a variable number of input arguments (instead of just 12).

Réponse acceptée

Walter Roberson
Walter Roberson le 18 Juin 2015
Read "Specify Input Arguments for Generated Function" in http://www.mathworks.com/help/symbolic/matlabfunction.html
So it would be like
matlabFunction(xdot_sym, {[p q s ...]})
where p q s ... is the list of variable names as they appear in xdot_sym; the first of them will be mapped to the first column of the single input, the second will be mapped to the second column of the single input, and so on.
  2 commentaires
Trevor
Trevor le 18 Juin 2015
This works great although isn't it necessary to include 'Vars' in your example code?
Walter Roberson
Walter Roberson le 18 Juin 2015
Yes, 'Vars' would be needed,
matlabFunction(xdot_sym, 'Vars', {[p q s ...]})

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox 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