I am trying to integrate the XSteam mfile in my simulink model through a MATLAB function block, only this error occurs: Variable 'hs' is undefined on some execution paths.
显示 更早的评论
This is what my own function file looks like:
function h = fcn(t,p)
%#codegen
h=XSteam('h_pt',p,t);
And this is de part where the error is referring to in the XSteam mfile:
function h4L_p = h4L_p(p)
if (p > 0.000611657 & p < 22.06395)==1
Ts = T4_p(p);
if p < 16.529
h4L_p = h1_pT(p, Ts);
else
%Iterate to find the the backward solution of p3sat_h
Low_Bound = 1670.858218;
High_Bound = 2087.23500164864;
ps=-1000;
while abs(p - ps) > 0.00001
hs = (Low_Bound + High_Bound) / 2;
ps = p3sat_h(hs);
if ps > p
High_Bound = hs;
else
Low_Bound = hs;
end
end
h4L_p = hs; ERROR OCCURS ON THIS LINE(line 2480 in XSteam)
if true
% code
end
end
else
h4L_p = -99999;
end
if true
% code
end
The complete XSteam mfile can be found at:
I already tried to place "persistent hs;" after function, but that didn't solve the problem.
2 个评论
saladin ghanem
2016-4-5
编辑:saladin ghanem
2016-4-5
Hi, I've found this code below and it worked for me.
function h10 = fcn(Pb)
%#codegen
coder.extrinsic('XSteam');
h10 = coder.nullcopy(zeros(size(Pb)));
h10=XSteam('hL_P',Pb);
You can change hL_P and play with you code. I hope you can make use of it.
Anwer Hamed
2017-8-2
Thank you very much saladin you script solved my problem
采纳的回答
更多回答(2 个)
Tarek Sobh
2014-2-23
0 个投票
Hello Arnoud, I'm basically trying to do the same thing, however, I'm getting the same errors that you used to get. Can you please elaborate on how you were able to solve the problem? Did you edit the XSteam.m file? Thanks.
1 个评论
Hi Tarek, probably you don't need this anymore but hopefully it might help someone else or yourself. What I did was check where the error was ocurring and found there is a while statement in which the hs is defined but it was being used outside of this while so if the condition of the loop was not met then h4V_p would equal to a variable which does not exist.
function h4V_p = h4V_p(p)
if (p > 0.000611657 & p < 22.06395)==1
Ts = T4_p(p);
if p < 16.529
h4V_p = h2_pT(p, Ts);
else
%Iterate to find the the backward solution of p3sat_h
Low_Bound = 2087.23500164864;
High_Bound = 2563.592004+5;
ps=-1000;
% hs not defined before while !! So add this line:
hs = (Low_Bound + High_Bound) / 2;
while abs(p - ps) > 0.000001
hs = (Low_Bound + High_Bound) / 2;
ps = p3sat_h(hs);
if ps < p
High_Bound = hs;
else
Low_Bound = hs;
end
end
% so it may not exist when used here
h4V_p = hs;
end
else
h4V_p = -99999;
end
saladin ghanem
2016-4-5
Hi, I've found this code below and it worked for me.
function h10 = fcn(Pb)
%#codegen
coder.extrinsic('XSteam');
h10 = coder.nullcopy(zeros(size(Pb)));
h10=XSteam('hL_P',Pb);
You can change hL_P and play with you code. I hope you can make use of it.
类别
在 帮助中心 和 File Exchange 中查找有关 Block and Blockset Authoring 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!