Are nested functions supported in live scripts? Otherwise, global variables have to be declared as global?

댓글 수: 6

"Are nested functions supported in live scripts?"
Yes.
"Otherwise, global variables have to be declared as global?"
global variables always need to be declared as global.
but I found that nested functions that function properly in m files report errors in live scripts, why?
Which functions gave you the error? And what was the error they gave?
feynman feynman
feynman feynman 2024년 2월 27일
편집: feynman feynman 2024년 2월 27일
the 'run' button isn't even clickable unless I delete the 1st 'function' and the final 'end' lines.
A function needs to be called by using its name and providing any inputs required to run it. That is the case in both functions (.m) and live functions (.mlx).
If, a function does not require any input to run, you can run it (.m file) by pressing the green button.
However, that is not the case with live function (.mlx file), for which you need to explicitly call it.
thanks so much

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

 채택된 답변

Cris LaPierre
Cris LaPierre 2024년 2월 27일
편집: Cris LaPierre 2024년 2월 27일

0 개 추천

Yes, MATLAB supports nested functions.However, you must call a function. You run a script.
To enable the Run button, at the very top of your live script, call your function.
sl
function sl
...
end
Note that the clear is unnecessary, as your function runs in tis own workspace. It will not have anything in it at this point.

추가 답변 (0개)

카테고리

질문:

2024년 2월 27일

댓글:

2024년 2월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by