matlab function syms slows down simulink model

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Steven Lord
Steven Lord il 27 Nov 2022
Generate a MATLAB Function block using matlabFunctionBlock as shown on this documentation page.
  2 Commenti
Bernd Pfeifer
Bernd Pfeifer il 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 il 28 Nov 2022
solved it with https://de.mathworks.com/help/symbolic/sym.matlabfunction.html

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Simulink in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by