MATLAB: Function ‘range_calculator’ has already been declared within this scope.

already been declared

I have the following driver file named 'Program 6':
[x]=range_calculator(a,b)
and the following function file named 'range_calculator'
g=9.9;
function[x]=range_calculator(a,b)
x= ((b^2)*sin(2*a))/g;
end
and I keep getting the error message above. Should I change the file name?
Thanks,

Best Answer

You may try removing the initialization of 'g' which is the first line in your function. In matlab, if you have code above the function definition inside your function file, it gets treated as a local function. So you will need to relocate your first line in the function to somewhere else or find another way to initialize 'g'.
Hope it Helps!
Related Question