function for m file
이전 댓글 표시
I was given the function:
g(x,y) = (x^2/y^4)+(cos(7*x*exp(9*y))/(x^6 + 2));
and was instructed to format it as an anonymous function:
g = @(x,y) (x^2/y^4)+(cos(7*x*exp(9*y))/(x^6 + 2));
When trying to create the m file, the contents were written as:
g = @(x,y) (x^2/y^4)+(cos(7*x*exp(9*y))/(x^6 + 2
function g = f(x,y)
g = (x^2/y^4)+(cos(7*x*exp(9*y))/(x^6 + 2));
end
When then trying to run the file, this error appears:
Error: File: g.m Line: 1 Column: 1
Using 'g' as both the name of a variable and the name of a script is not supported.
The file is to be named g.m and be called using g(x,y), x and y being any number, as per assignment instructions. What is causing the file not to run?
댓글 수: 1
"What is causing the file not to run?"
The error message already tells you exactly what the problem is. Lets read it:
"Using 'g' as both the name of a variable and the name of a script is not supported."
Lets look at the information you gave about the script name:
"The file is to be named g.m ..."
Lets look at the information you gave about the variable name:
function g = f(..)
g = (..);
end
So you clearly used g for both the filename as well as the name of a variable. Which the error message clearly states is not allowed. If the error message unclear, how could it be improved?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!