## User Input Error? Using input in a function

on 27 Feb 2019

### Stephan (view profile)

on 28 Feb 2019
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.

Olivia Colombo

### Olivia Colombo (view profile)

on 28 Feb 2019
Error using mydistance (line 4)
Error: Invalid expression. Check for missing multiplication operator,
missing or unbalanced delimiters, or other syntax error. To construct
matrices, use brackets instead of parentheses.
Walter Roberson

### Walter Roberson (view profile)

on 28 Feb 2019
exactly what input are you typing in in response to the prompt ?
Olivia Colombo

### Olivia Colombo (view profile)

on 28 Feb 2019
I've been testing it with: (with and without various degree symbols)
37N, 76W 37N 9W

### Stephan (view profile)

on 28 Feb 2019

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,""))));
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