フィルターのクリア

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 Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by