Undefined function or Variable while calling function.

Program works fine by itself, but when I call it to another m file the error below occurs.
Command Window :
Undefined function or variable 'ang'.
Error in Degree_to_NorthAZM (line 26)
DTNA =[ang min sec];
Editor :
function [DTNA] = Degree_to_NorthAZM(angle, Direction)
% This function converts angle = [Degree Minute Second] into North AZM
% Direction 1, 2, 3 and 4 are respectively NW, NE, SE and SW
if Direction == 1
ang = 359 - angle(1,1);
min = 59 - angle(1,2);
sec = 60 - angle(1,3);
elseif Direction == 2
ang = angle(1,1);
min = angle(1,2);
sec = angle(1,3);
elseif Direction == 3
ang = 179 - angle(1,1);
min = 59 - angle(1,2);
sec = 60 - angle(1,3);
elseif Direction == 4
ang = 180 + angle(1,1);
min = angle(1,2);
sec = angle(1,3);
end % End of If else loop
DTNA =[ang min sec]; % Function output
end % End of Function

6 件のコメント

Walter Roberson
Walter Roberson 2018 年 3 月 31 日
How are you invoking the function? And which item is it complaining does not exist?
Question: what happens if Direction is not one of those four values? What happens if Direction is a vector of those values?
Ashikul Yousuf
Ashikul Yousuf 2018 年 3 月 31 日
編集済み: Ashikul Yousuf 2018 年 3 月 31 日
Variable 'ang'. The Direction has to be one of those 4.
Walter Roberson
Walter Roberson 2018 年 3 月 31 日
Please give an example of how you are invoking the function.
Ashikul Yousuf
Ashikul Yousuf 2018 年 3 月 31 日
編集済み: Walter Roberson 2018 年 3 月 31 日
angle = input('Please enter bearing [Degrees Minute Second]');
Direction = input('Please enter 1,2,3 or 4 to NW NE SE SW','s');
% Function call to convert Angle and direction to North AZM
DTNA = Degree_to_NorthAZM(angle, Direction)
Ashikul Yousuf
Ashikul Yousuf 2018 年 3 月 31 日
I found the issue.
Direction = input('Please enter 1,2,3 or 4 to NW NE SE SW','s');
Direction isn't defined as string in the function. Thanks for the quick replies.
Walter Roberson
Walter Roberson 2018 年 3 月 31 日
Yes, that would do it.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2018 年 3 月 31 日

コメント済み:

2018 年 3 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by