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
per isakson 2014 年 10 月 28 日
"I have the following 2 functions:" &nbsp but you show two listings of the same function. Anyhow, I don't see any difference.

サインインしてコメントする。

 採用された回答

per isakson
per isakson 2014 年 10 月 28 日
編集済み: per isakson 2014 年 10 月 28 日

0 投票

"Error in plotShot (line 2) hits=hitPond(pondRadius, xhit, yhit)" &nbsp one output, &nbsp hits &nbsp is expected but there is no output returned by the function
function hitPond(pondRadius, xhit, yhit)

3 件のコメント

Andrew Ardolino
Andrew Ardolino 2014 年 10 月 28 日
ugh, i'm not sure how to fix it
Andrew Ardolino
Andrew Ardolino 2014 年 10 月 28 日
like, I want to make it so that the output from hitPond can be used in a different function to plot it under certain circumstances
per isakson
per isakson 2014 年 10 月 28 日
編集済み: per isakson 2014 年 10 月 28 日
It seems as if the calling function, &nbsp plotShot, &nbsp assumes the function, &nbsp hitPond, &nbsp to calculate and return &nbsp hits. &nbsp 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 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2014 年 10 月 28 日

編集済み:

2014 年 10 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by