User Input Error? Using input in a function
10 次查看(过去 30 天)
显示 更早的评论
I am trying to use input to make a functiont that calculates the great circle distance between two sets of coordinates on the surface of the Earth. The problem is I am getting an error on the part that takes input (line 4), long before I get to the calculations. What am I doing wrong?
I've attached the code as well as example coordinates to check it.
7 个评论
回答(1 个)
Stephan
2019-2-28
Hi,
try:
result = mydistance
function d = mydistance
prompt = 'Input coordinates between which you want to find the great circle distance (XºN, XºW XºN, XºW): \n';
getridof = ["N","W",",",char(176)];
x = input(prompt,'s');
x = double(string(split(replace(x,getridof,""))));
a = acos(sin(deg2rad(x(1)))*sin(deg2rad(x(3)))+cos(deg2rad(x(1)))*cos(deg2rad(x(3)))*cos(abs(deg2rad(x(2)))-deg2rad(x(4))));
d = a*.6371;
disp(['The great circle distance in km is: ',num2str(d)])
end
for input:
Input coordinates between which you want to find the great circle distance (XºN, XºW XºN, XºW):
37°N, 76°W 37°N, 9°W
the result is:
The great circle distance in km is: 0.58165
result =
0.5817
Best regards
Stephan
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!