Rename arguments of generated function with `matlabFunction`

1 vue (au cours des 30 derniers jours)
Robert Roos
Robert Roos le 28 Mai 2019
Modifié(e) : Robert Roos le 28 Mai 2019
I have a script that generated matlab functions based on some kinematic calculations. I need to pair up variables in vectors as functions arguments. However, when I do this the arguments are named `in1`, `in2`, etc., which is makes the functions very inconvenient to use.
Example:
syms x1 x2 x3 f;
f = sqrt(x1^2 + x2^2 + x3^2);
x_vec = [x1; x2; x3];
matlabFunction(f, 'file', 'myfunc.m', 'vars', {x_vec});
The resulting function will be:
function f = myfunc(in1)
%MYFUNC
% F = MYFUNC(IN1)
% ...
How can I rename the function argument? (without renaming it manully in the result of course, because I will be regenerating the functions a lot.)
It is not much of a problem in this trivial example, but in my real code I have functions with five different vector inputs.
Using a vector to begin with instead of separate variables doesn't help:
x = sym('x', [3,1]);
syms f;
f = sqrt(x(1)^2 + x(2)^2 + x(3)^2);
matlabFunction(f, 'file', 'myfunc.m', 'vars', {x});
function f = myfunc(in1)
%MYFUNC
% F = MYFUNC(IN1)

Réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by