Borrar filtros
Borrar filtros

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

4 visualizaciones (últimos 30 días)
Kamia Kavi
Kamia Kavi el 22 de Dic. de 2022
Respondida: Sarthak el 9 de Feb. de 2023
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 comentarios
Mathieu NOE
Mathieu NOE el 22 de Dic. de 2022
never use matlab function names as variables
you code should be
function max_value = find_value
max_value = max([10 100]);
end

Iniciar sesión para comentar.

Respuestas (1)

Sarthak
Sarthak el 9 de Feb. de 2023
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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by