フィルターのクリア

Error by having similar names for a variable and a MATLAB function

5 ビュー (過去 30 日間)
Kamia Kavi
Kamia Kavi 2022 年 12 月 22 日
回答済み: Sarthak 2023 年 2 月 9 日
When the name of the output variable (max) is similar to the name of function (max), I get the error of "Unrecognized function or variable 'max'. Why does it happen?
function max = find_value
max = max([10 100]);
end
  3 件のコメント
Kamia Kavi
Kamia Kavi 2022 年 12 月 22 日
Thanks!
Mathieu NOE
Mathieu NOE 2022 年 12 月 22 日
never use matlab function names as variables
you code should be
function max_value = find_value
max_value = max([10 100]);
end

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

回答 (1 件)

Sarthak
Sarthak 2023 年 2 月 9 日
Hi,
In MATLAB, when you have a variable with the same name as a built-in function, MATLAB will use the variable instead of the function. To resolve this conflict, you can simply change the name of the output variable to something else. Please refer the following code for reference:
function max_value = find_value
max_value = max([10 100]);
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by