MATLAB Answers

Function 'range_calculator' has already been declared within this scope.

110 views (last 30 days)
rjp94 on 29 Mar 2020
Answered: Athul Prakash on 3 Apr 2020
I have the following driver file named 'Program 6':
and the following function file named 'range_calculator'
x= ((b^2)*sin(2*a))/g;
and I keep getting the error message above. Should I change the file name?

  1 Comment

Rik on 29 Mar 2020
It looks like you are trying to run a script that contains an internal function with the same name. You should not put any code before the first function definition if you intend a file to work as a function.

Sign in to comment.

Accepted Answer

Athul Prakash
Athul Prakash on 3 Apr 2020
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!


Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by