when i write functions in matlab it not recognizing?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Aravind Mallemputi
el 24 de Oct. de 2021
Comentada: Image Analyst
el 24 de Oct. de 2021
function [hNest,hLocal] = functionsExample(v)
hNest = @nestFunction;
hLocal = @localFunction;
function y = nestFunction(x)
y = x + v;
end
end
function y = localFunction(z)
y = z + 1;
end
2 comentarios
Jan
el 24 de Oct. de 2021
This is some code. What is the problem? Do you get an error message? If so, which one? When does the message appear, or in other words: how do you call this function?
Respuesta aceptada
Image Analyst
el 24 de Oct. de 2021
It ran for me with no errors.
Note that you never actually call either nestFunction() or localFunction(). You just assign function handles and exit. So, they never actually use your x, y, v, or z variables. Just leave off the semicolon when you call
[hNest,hLocal] = functionsExample(5)
or set a break point in those functions to verify that fact.
4 comentarios
Image Analyst
el 24 de Oct. de 2021
@Aravind Mallemputi reply moved here:
you helped me a lot Tqu you sir,its working.
Image Analyst
el 24 de Oct. de 2021
@Aravind Mallemputi, good. My guess is that you just posted some simplified, dummy code that was not what you actually were running. And then you realized that you needed to call the internal, nexted functions -- they do not automatically call themselves. If I helped you, you can "Accept" or Vote for this answer.
Más respuestas (0)
Ver también
Categorías
Más información sobre Function Creation 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!