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

7 ビュー (過去 30 日間)
rjp94
rjp94 2020 年 3 月 29 日
回答済み: Athul Prakash 2020 年 4 月 3 日
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,
  1 件のコメント
Rik
Rik 2020 年 3 月 29 日
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.

サインインしてコメントする。

採用された回答

Athul Prakash
Athul Prakash 2020 年 4 月 3 日
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!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by