Error trying to use Nested Functions: Not shared Variable

9 ビュー (過去 30 日間)
Eric VALETTE
Eric VALETTE 2018 年 7 月 19 日
コメント済み: Walter Roberson 2018 年 7 月 19 日
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 件のコメント
Walter Roberson
Walter Roberson 2018 年 7 月 19 日
"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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by