- you have saved the function as a local function (i.e. after some other code in script or after another function),
- you have saved the Mfile somewhere that is not on the MATLAB Search Path.
Why is my function not recognized?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
TheSaint
el 9 de Feb. de 2024
Comentada: Stephen23
el 9 de Feb. de 2024
function myEquation (x)
a = 0.4361836;
b = 0.1201676;
c = 0.937298;
r = (e^(-0.5*(x^2)))/(2*pi)
t = 1/(1+(0.3326*x))
phi = 0.5 - r*((a*t)-(b*(t^2))+(c*(t^3)))
fprintf('The value of Φ(x) is: %i', phi)
fprintf('\n')
end
This is my current code. I am trying to use it to solve for the value of phi, and then print it. However, when I try to call it from the Command Window, it just says it is an unrecognized variable or function.
1 comentario
Stephen23
el 9 de Feb. de 2024
"However, when I try to call it from the Command Window, it just says it is an unrecognized variable or function."
Most likely:
Respuesta aceptada
VBBV
el 9 de Feb. de 2024
myEquation(2)
function myEquation (x)
a = 0.4361836;
b = 0.1201676;
c = 0.937298;
r = exp(-0.5*(x^2))/(2*pi)
t = 1/(1+(0.3326*x))
phi = 0.5 - r*((a*t)-(b*(t^2))+(c*(t^3)))
fprintf('The value of Φ(x) is: %i', phi)
fprintf('\n')
end
3 comentarios
Stephen23
el 9 de Feb. de 2024
Editada: Stephen23
el 9 de Feb. de 2024
"How would I call this from the command window?"
Like this:
myEquation(2)
What is probably more important is where you have saved that function:
- it must be the main function in an Mfile (i.e. it cannot be a local function or a nested function or part of a script),
- the Mfile must be on the MATLAB Search Path (simplest is to save it in the current directory).
Más respuestas (0)
Ver también
Categorías
Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!