Rename arguments of generated function with `matlabFunction`

1 次查看(过去 30 天)
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)

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by