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

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

回答(1 个)

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

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

提问:

2022-12-22

回答:

2023-2-9

Community Treasure Hunt

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

Start Hunting!

Translated by