필터 지우기
필터 지우기

Rename arguments of generated function with `matlabFunction`

조회 수: 1 (최근 30일)
Robert Roos
Robert Roos 2019년 5월 28일
편집: Robert Roos 2019년 5월 28일
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