Error by having similar names for a variable and a MATLAB function
조회 수: 4 (최근 30일)
이전 댓글 표시
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
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
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Downloads에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!