matlab function syms slows down simulink model

1 Ansicht (letzte 30 Tage)
Bernd Pfeifer
Bernd Pfeifer am 27 Nov. 2022
Kommentiert: Bernd Pfeifer am 28 Nov. 2022
Hi,
i want to calculate the syms function y in a matlab function block in simulink . There is a slow and a fast option:
slow option:
matlab function in simulink:
------------------------
function y = fcn(v)
coder.extrinsic('calc_y') % is needed, otherwise simulink prints an error
y =0;
y = calc_y(v);
------------------------
which calls the extrinsic matlab function:
------------------------
function y = calc_y(v)
y = evalin('base','y'); % Read syms function y from workspace
y = double(subs(y,v));
------------------------
y is a syms function in the workspace : y =2v +v +5; % dummy function
The code works, but it is very slow.
fast option:
The fast solution is to copy y in the matlab function block like:
matlab function in simulink:
------------------------
function y = fcn(v)
y =2v +v +5; % no syms function anymore
------------------------
y is calculated in matlab init file and can be changed in the initialization. So with the fast option i need to copy the y function everytime by hand.
The problem of the caluclation speed is the syms function.
Is there any workaround to not declare it as syms function and copy the function automatically in the matlab function block in simulink?
Thanks and Regards!
Bernd

Akzeptierte Antwort

Steven Lord
Steven Lord am 27 Nov. 2022
Generate a MATLAB Function block using matlabFunctionBlock as shown on this documentation page.
  2 Kommentare
Bernd Pfeifer
Bernd Pfeifer am 27 Nov. 2022
Perfect thanks, that worked!
But is it possible to generate the Matlab Function Block in a subsystem?
Regards
Bernd
Bernd Pfeifer
Bernd Pfeifer am 28 Nov. 2022
solved it with https://de.mathworks.com/help/symbolic/sym.matlabfunction.html

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by