Output argument "D" (and maybe others) not assigned during call to "E:\PRO\NNEWPTR\MRG.m>MRG".
조회 수: 2 (최근 30일)
이전 댓글 표시
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".
I have tried by using link http://www.mathworks.com/matlabcentral/answers/97825-why-do-i-get-the-error-output-argument-variable-and-maybe-others-not-assigned-during-call-t but unable to solve it.
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...............
댓글 수: 0
채택된 답변
Geoff Hayes
2015년 11월 28일
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
Image Analyst
2015년 11월 28일
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.
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!