Help with Function Errors?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have the following 2 functions:
function hitPond(pondRadius, xhit, yhit)
%use distance formula to find length between points.
x=0;
y=0;
%because of the axis^
%we are finding the distance between the axis and the point where it hit
step1=(xhit-x)^2;
step2=(yhit-y)^2;
step3=step1+step2;
distance=sqrt(step3);
if (distance<1);
output_variablePond = 1;
disp(output_variablePond)
elseif distance>1;
output_variableField =0;
disp(output_variableField)
end
end
and
function hitPond(pondRadius, xhit, yhit)
%use distance formula to find length between points.
x=0;
y=0;
%because of the axis^
%we are finding the distance between the axis and the point where it hit
step1=(xhit-x)^2;
step2=(yhit-y)^2;
step3=step1+step2;
distance=sqrt(step3);
if (distance<1);
output_variablePond = 1;
disp(output_variablePond)
elseif distance>1;
output_variableField =0;
disp(output_variableField)
end
end
when I run them in my driver script, I get errors
Error using hitPond Too many output arguments.
Error in plotShot (line 2) hits=hitPond(pondRadius, xhit, yhit)
Error in monteCarlo (line 22) plotShot(1,0,0)
Can anyone explain to me what I'm doing wrong?
Thanks in advance.
댓글 수: 1
per isakson
2014년 10월 28일
"I have the following 2 functions:"   but you show two listings of the same function. Anyhow, I don't see any difference.
채택된 답변
per isakson
2014년 10월 28일
편집: per isakson
2014년 10월 28일
"Error in plotShot (line 2) hits=hitPond(pondRadius, xhit, yhit)"   one output,   hits   is expected but there is no output returned by the function
function hitPond(pondRadius, xhit, yhit)
댓글 수: 3
per isakson
2014년 10월 28일
편집: per isakson
2014년 10월 28일
It seems as if the calling function,   plotShot,   assumes the function,   hitPond,   to calculate and return   hits.   However, the listing doesn't show any such calculation and there is no output.
Did you study the examples in the page I linked to?
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!