Getting two outputs when using function with implemented if statement
2 ビュー (過去 30 日間)
古いコメントを表示
Alexander Jørgensen
2020 年 12 月 30 日
コメント済み: Paul Hoffrichter
2020 年 12 月 30 日
Hey, I'm all new to MatLab and would like to know why I'm getting two outputs when using the following code:
function theta = acuteAngle(v1,v2)
theta = acos((dot(v1,v2)));
if theta > pi/2
disp(pi-theta);
else
disp(theta);
end
end
Result i get with following input:
Input:
disp(acuteAngle([-4/5, 3/5], [20/29, 21/29]))
Output: (i only want the first result : 1.4533)
1.4533
1.6883
0 件のコメント
採用された回答
Paul Hoffrichter
2020 年 12 月 30 日
編集済み: Paul Hoffrichter
2020 年 12 月 30 日
In your acuteAngle function, there is a disp() line which gives you the first output. The calling routine disp(acuteAngle() gives you the second output.
To get only the first output, call the function like this:
acuteAngle([-4/5, 3/5], [20/29, 21/29]); % the semi-colon suppresses the output
2 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!