if nested functions supported in live scripts

6 Ansichten (letzte 30 Tage)
feynman feynman
feynman feynman am 27 Feb. 2024
Kommentiert: feynman feynman am 27 Feb. 2024
Are nested functions supported in live scripts? Otherwise, global variables have to be declared as global?
  6 Kommentare
Dyuman Joshi
Dyuman Joshi am 27 Feb. 2024
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.
feynman feynman
feynman feynman am 27 Feb. 2024
thanks so much

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 27 Feb. 2024
Bearbeitet: Cris LaPierre am 27 Feb. 2024
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.

Weitere Antworten (0)

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by