when i write functions in matlab it not recognizing?

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

Jan
Jan 2021년 10월 24일
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?
Run option is not activated

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2021년 10월 24일
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

Run option is not showing and the code is working for another pc it's not working on my laptop.
Exactly what does "not working" mean to you? Does it throw an error? Download and run my test6.m file. Does it run?
@Aravind Mallemputi reply moved here:
you helped me a lot Tqu you sir,its working.
@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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2021년 10월 24일

댓글:

2021년 10월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by