Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I don't find the error in my function, (index exceed matrix dimensions)?

1 回表示 (過去 30 日間)
Fernando Alan Gomez
Fernando Alan Gomez 2017 年 10 月 1 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
function [ EAngle ] = Azimuth( A,B )
vDelta1 = B-A
angle1 = atan(vDelta(1)/vDelta(2)))
angle1 = abs(rad2deg(angle1))
vDelta2 = (B-A)
%
if vDelta2(1)>0 && vDelta2(2)>0
disp(angle1)
end
if vDelta2(1)>0 && vDelta2(2)<0
disp(180-angle1)
end
if vDelta2(1)<0 && vDelta2(2)<0
disp(180+angle1)
end
if vDelta2(1)<0 && vDelta2(2)>0
disp(360-angle1)
end
end
  1 件のコメント
per isakson
per isakson 2017 年 10 月 1 日
I tried your code and I get a different error message
>> Azimuth( pi/2, pi/3 )
Error: File: Azimuth.m Line: 3 Column: 39
Unbalanced or unexpected parenthesis or bracket.
  • How do you call the function?
  • Show us the full error message.

回答 (1 件)

Ramnarayan Krishnamurthy
Ramnarayan Krishnamurthy 2017 年 10 月 4 日
I am assuming that you are calling the function with vector arguments such as: Azimuth([10,20],[30,40]).
Now, there is an extra bracket in the 3rd line of the function. Change it to:
angle1 = atan(vDelta1(1)/vDelta1(2))
The function can now be called with vector inputs.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by