Problem with "assignin" in combination with "Interpreted MATLAB Function"

1 visualización (últimos 30 días)
Klaas Albers
Klaas Albers el 20 de Jun. de 2019
Editada: Klaas Albers el 20 de Jun. de 2019
Hello,
I´m currently working on the Simulation of a heat exchanger in combination with a controll system in Simulink. I wrote a function in Matlab to solve a differential equation and call this script via a Interpreted MATLAB Function Block in Simulink. The code looks as the following:
function [T_ww] = Definition_of_Tww(T_rl)
%Constants
m_ii=evalin('base','m_i');
c_pp=evalin('base','c_p');
m_pkt11=evalin('base','m_pkt1');
m_pkt22=evalin('base','m_pkt2');
T_vll=evalin('base','T_vl');
T_wkk=evalin('base','T_wk');
%Calculations
c_1=m_ii*c_pp;
c_2=c_1;
c_pkt1=c_pp*m_pkt11;
c_pkt2=c_pp*m_pkt22;
syms T_w(t);
cond = T_w(0)==273.15+15;
eqn = c_1*diff((T_vll-T_rl),t)-c_pkt1*(T_vll-T_rl)==c_2*diff((T_wkk-T_w),t)-c_pkt2*(T_wkk-T_w);
T_ww=dsolve(eqn,cond);
end
To solve this differential equation i need both massflows in the heat exchanger. I´m transporting them to the Matlab base Workspace via a Matlab function in Simulink with the following code:
function z = fcn(w)
coder.extrinsic('assignin');
assignin('base','m_pkt1',w);
z = w;
The function for m_pkt2 is analog. I tested this function in a seperat Simulink project with a Sine Wave Block and a Profile for m_pkt2 witch i want to Simulate with and it worked there. But in the normal project only m_pkt2 gets passed over to the base Workspace. With a Simple "sin" in the Interpreted MATLAB Function Block m_pkt1 actually gets passed to the base Workspace. I tried some things so far but nothing worked.
I hope somebody can help me with this Problem.
Kind Regards

Respuestas (0)

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by