matlab function syms slows down simulink model

조회 수: 2(최근 30일)
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!

채택된 답변

Steven Lord
Steven Lord 2022년 11월 27일
Generate a MATLAB Function block using matlabFunctionBlock as shown on this documentation page.
  댓글 수: 2
Bernd Pfeifer
Bernd Pfeifer 2022년 11월 28일
solved it with

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by