Error trying to use Nested Functions: Not shared Variable
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I'm currently trying to write my script using Nested Functions in the aim to use less memory space with the inputs-variables calls.
And so, when I'm calling my parent function, it returns me: "Error using cumsum CUMSUM supports only numerical or logical inputs."
and in fact, I'm using cumsum(A) where A is normally the result of my Nested function, but it doesn't seem to operate because A doesn't appear in the workspace... I've tried to create A=[] before calling the Nested function but it didn't change any thing.
Does someone know what could be the problem please ?
Thank you in advance and have a nice day,
Eric
Could someone tell me if the anterior way of writing it is a convenient structure please
1 Kommentar
Walter Roberson
am 19 Jul. 2018
"I'm currently trying to write my script using Nested Functions in the aim to use less memory space with the inputs-variables calls."
When you pass a variable into a function, the corresponding variable in the called function shares memory with the original, unless you modify the variable inside the function (in which case a duplicate of the original is made and the duplicate is changed.)
Therefore, using shared variables only saves memory if the shared variable is modified -- but if it is modified then all references to the shared variable acquire the new value, which destroys software encapsulation and typically makes it much harder to understand the code.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Variables 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!