How to define a nested function inside a for loop?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I wish to define a nested function inside a for loop. When I did it I encountered an error. When I further inquired I found the following:
``You cannot define a nested function inside any of the MATLAB® program control statements, such as if/elseif/else, switch/case, for, while, or try/catch."
which is available at
https://www.mathworks.com/help/matlab/matlab_prog/nested-functions.html#btfml3d
Any by pass to this? Can I define a nested function inside a loop?
Thank you.
4 Kommentare
Matt J
am 1 Dez. 2017
Your attached files contain neither loops nor nested functions. They therefore cannot clarify where you are trying to place a nested function, nor why you think it needs to go inside a loop.
Antworten (1)
Matt J
am 1 Dez. 2017
Bearbeitet: Matt J
am 1 Dez. 2017
There should be no need to place a nested function definition inside a loop. My advice would be to simply move it outside the loop, placing it somewhere else in the same workspace. As long as the nested function resides in the same workspace as the loop, they should both have access to all variables in that workspace.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!