Invalid expression error with function!
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I am new to using a function, and I'm trying to make a function mydistance that will take user input of coordinates and then calculate the great circle distance on the surface of the earth between the coordinates. The equation is all in there, but I am getting an error on the part that asks for input. Any ideas? Thank you!
(I've been trying it using the input: 37N, 76W 37N, 9W)
function d = mydistance(a)
prompt = 'Input coordinates between which you want to find the great circle distance (XN, XW XN, XW): ';
getridof = ["N","W",","];
x = input(prompt)
x = split(replace(x,getridof," "));
a = acos(sin(x(1))*sin(x(3))+cos(x(1))*cos(x(3))*cos(abs(x(2))-x(4)));
d = a*.6371;
disp(['The great circle distance in km is: ',num2str(d)])
end
0 Kommentare
Antworten (1)
Star Strider
am 28 Feb. 2019
Read the coordinates as a string, then do the conversions:
prompt = 'Input coordinates between which you want to find the great circle distance (XN, XW XN, XW): ';
getridof = ["N","W",","];
xc = input(prompt, 's')
xc = split(replace(xc,getridof," "));
x = str2double(xc)
a = acos(sin(x(1))*sin(x(3))+cos(x(1))*cos(x(3))*cos(abs(x(2))-x(4)));
d = a*.6371;
disp(['The great circle distance in km is: ',num2str(d)])
This works, and with your desired inputds, produces:
The great circle distance in km is: 0.93002
when I run it.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Earth, Ocean, and Atmospheric Sciences finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!