Output argument "D" (and maybe others) not assigned during call to "E:\PRO\NN​EWPTR\MRG.​m>MRG".

3 views (last 30 days)
Hi , I am using forth order RK method to solve my probolem.But while calling one subfunction MRG.m to main function i am getting error message
Output argument "D" (and maybe others) not assigned during call to
"E:\PRO\NNEWPTR\MRG.m>MRG".
here is the code of MRG.m
function [D]= MRG(p_cp,p_t)
rho=2.389;
drg=.032;
dh=.04E-3;
lrg=.8;
mu=15.21E-6;
phi=.7;
r=2074;
t1=(rho*pi*drg*drg*dh*dh)/(600*lrg*mu);
t2=(phi*phi*phi)/(1-phi);
if(p_cp>p_t)
D=t1*t2*(p_cp-p_t);
elseif(p_cp>p_t)
D=t1*t2*(p_t-p_cp);
elseif(p_cp==p_t)
D=0;
end
The main function code which is related to this function is
for m=1:1:100
v_cp=vo+(0.5*vs*(1+sin(omega*t(m))));
v_cpdot=vs*pi*f*cos(omega*t(m));
m_o=MO(p_t(m),p_r(m));
m_rg=MRG(p_cp(m),p_t(m));
end,
Actually it is a part of code of main function,I have not attached the detailed code becz it will be difficult to understtod if required i will send.
plz help...............

Accepted Answer

Geoff Hayes
Geoff Hayes on 28 Nov 2015
Debashis - if you put a breakpoint in your function MRG, call it, and then step through the code using the debugger you will probably find that none of the conditions in the if and elseif block are satisfied, and so D is never instantiated...hence the error that the output parameter D is not assigned any value.
The first line of MRG should initialize this value (and any other output values if they exist) to some default value. In this case,
D = [];
would be sufficient. This will solve the problem given by the error message, but it will not solve the why none of the conditions are being satisfied. Again, use the debugger to make sure that the provided inputs make sense and that the conditions make sense too. I suspect the problem is with your second condition which is the same as the first
if(p_cp>p_t)
D=t1*t2*(p_cp-p_t);
elseif(p_cp>p_t)
D=t1*t2*(p_t-p_cp);
The second condition should probably be
elseif(p_cp<p_t)
(just swap the greater than to a less than).
  2 Comments
DEBASHIS PANDA
DEBASHIS PANDA on 28 Nov 2015
Thankyuou very much sir , Actually i have modeled the equation like (p_cp<p_t),unfortunately while typing i have typed wrong,thankyou onceagain....
Image Analyst
Image Analyst on 28 Nov 2015
That was not the problem of the error. The problem was that if none of the 3 conditions in your if/else were satisfied, D would never get assigned a value. You can assign it null, like Geoff showed you as soon as you enter the function, before the if/else, and that will solve the problem.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!