Borrar filtros
Borrar filtros

matlab embedded fuction in simulink

24 visualizaciones (últimos 30 días)
Ahmed Tolba
Ahmed Tolba el 14 de Mayo de 2012
Editada: Tianji Li el 25 de Abr. de 2019
I have used an m file named('XSteam.m') and I wanted to make a simulink model from this m file then I have made the embedded function code as the following
function [t,p,h,hv,hl,v,v_v,vl,s,sv,sl,u,uv,ul,x] = fcn(t1,p1,h1,v1,s1,u1,x1)
%#eml
eml.extrinsic('XSteam')
coder.extrinsic('XSteam');
if ((t1==0)&& (h1==0)&& (v1==0)&& (s1==0)&& (u1==0)&&(x1==0));
t=XSteam('Tsat_p',p1);
p=0;
hv=XSteam('hV_p',p1);
hl=XSteam('hL_p',p1);
v_v=XSteam('vV_p',p1);
vl=XSteam('vL_p',p1);
sv=XSteam('sV_p',p1);
sl=XSteam('sL_p',p1);
uv=XSteam('uV_p',p1);
ul=XSteam('uL_p',p1);
h=0;
u=0;
s=0;v=0;x=0;
elseif ((p1==0)&&(h1==0)&&(v1==0)&&(s1==0)&&(u1==0)&&(x1==0));
p=XSteam('psat_T',t1);
hv=XSteam('hV_T',t1);
hl=XSteam('hL_T',t1);
v_v=XSteam('vV_T',t1);
vl=XSteam('vL_T',t1);
sv=XSteam('sV_T',t1);
sl=XSteam('sL_T',t1);
uv=XSteam('uV_T',t1);
ul=XSteam('uL_T',t1);
t=0;
h=0;u=0;s=0;v=0;
elseif ((h1==0)&&(v1==0)&&(s1==0)&&(u1==0)&&(x1==0));
h=XSteam('h_pT',p1,t1);
s=XSteam('s_pT',p1,t1);
v=XSteam('v_pT',p1,t1);
u=XSteam('u_pT',p1,t1);
p=0;ul=0;uv=0;sl=0;sv=0;v_v=0;vl=0;hv=0;hl=0;x=0;
t=0;
elseif ((t1==0)&&(h1==0)&&(v1==0)&&(u1==0)&&(x1==0));
x=XSteam('x_ps',p1,s1);
u=XSteam('u_ps',p1,s1);
v=XSteam('v_ps',p1,s1);
t=XSteam('T_ps',p1,s1);
p=0;
s=0;ul=0;uv=0;sl=0;sv=0;v_v=0;vl=0;hv=0;hl=0;
elseif ((t1==0)&&(v1==0)&&(s1==0)&&(u1==0)&&(x1==0))
t=XSteam('T_ph',p1,h1);
v=XSteam('v_ph',p1,h1);
s=XSteam('s_ph',p1,h1);
u=XSteam('u_ph',p1,h1);
x=XSteam('x_ph',p1,h1);
p=0;
h=0;ul=0;uv=0;sl=0;sv=0;v_v=0;vl=0;hv=0;hl=0;
elseif ((t1==0)&&(v1==0)&&(u1==0)&&(p1==0)&&(x1==0))
t=XSteam('T_hs',h1,s1);
p=XSteam('p_hs',h1,s1);
h=0;s=0;ul=0;uv=0;sl=0;sv=0;v_v=0;vl=0;hv=0;hl=0;x=0;
else
h=XSteam('h_px',p1,x1);
u=0;s=0;p=0;x=0;ul=0;uv=0;sl=0;sv=0;v_v=0;vl=0;hv=0;hl=0;
end
then the model didn't work
and error messages appeared
I don't know the reasons for that because I am beginner in Simulink
If any one Can help me I will be grateful
[Merged information from duplicate question]
but when I run the model some errors display ""Sampled update was specified and no sample time was entered in chart Embedded MATLAB Function (#18)""
and ""Error reported by S-function 'sf_sfun' in 'steam/Embedded MATLAB Function/ SFunction ': Stateflow Suppress Error.""
  1 comentario
TAB
TAB el 15 de Mayo de 2012
First of all your code is not readable at all.
Please format the code properly and specify which errors you are getting?

Iniciar sesión para comentar.

Respuestas (2)

Mike Hosea
Mike Hosea el 15 de Mayo de 2012
I don't know anything about XSteam, but whenever you use an extrinsic function call, you need to pre-declare the output so that the compiler knows what the data type coming back from MATLAB is supposed to be before the model runs. Delete the eml.extrinsic line and keep the coder.extrinsic. Now, before any calls to XSteam, make sure the return variable is properly defined already. For example, if XSteam('T_ph',pl,hl) returns a 3-by-1 vector that is a 'uint8', then we should see
t = zeros(3,1,'uint8');
t = XSteam('T_ph',pl,hl);
It looks redundant, but that's how you do it, and the compiler knows better than to actually do both assignments. The first assignment just tells it that the data coming back from the extrinsic call is a 3-by-1 vector of 'uint8'. Of course you don't have to repeat the declarations in each case--you can collect them into one set at the top, before the if/elseif/elseif/.../else/end section.
You may have trouble with Simulink if any of the return types are different depending on which case is used. Make sure all the outputs are always the same class, size, and complexity (i.e., real or complex).
  2 comentarios
Ahmed Tolba
Ahmed Tolba el 16 de Mayo de 2012
but I am still having error
??? Error using ==> sf
Sampled update was specified and no sample time was entered in
chart Embedded
MATLAB Function (#18)
how can overcome this problem
Kaustubha Govind
Kaustubha Govind el 18 de Mayo de 2012
Strange error for an Embedded MATLAB Function block. I'm not sure if this is a legitimate error - try reporting this to MathWorks Tech Support and see if they are able to provide a resolution?

Iniciar sesión para comentar.


Tianji Li
Tianji Li el 25 de Abr. de 2019
Editada: Tianji Li el 25 de Abr. de 2019
you should input the "Sample time" or just change "Update method" to "Inherited".
You can find them in "Model Exploer".
111.JPG

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by