How can I make a variable span multiple functions for nested structuring?

13 ビュー (過去 30 日間)
Fulvio Cordella
Fulvio Cordella 2021 年 7 月 1 日
コメント済み: Fulvio Cordella 2021 年 7 月 2 日
I am recording and analyzing audio signals in real time and I need an index to everytime make a segmentation. I cheked up the documentation but I didn't find anything on how to, in poor words, make the variable "appearing cyan".

採用された回答

Stephen23
Stephen23 2021 年 7 月 1 日
編集済み: Stephen23 2021 年 7 月 1 日
How to make a variable "cyan" (these are called shared variables) is explained here:
In general, the shared variable must be defined in the parent workspace and referred to (or redefined) in the nested function. For more details, read the paged linked above.
Because this forum does not use the same highlighting as the installed MATLAB application, here is a screenshot (this function is also attached) showing the cyan shared variable:
  3 件のコメント
Stephen23
Stephen23 2021 年 7 月 2 日
編集済み: Stephen23 2021 年 7 月 2 日
"I only need to declare and assign value to the variable in the parent fcn and use it in the secondary fcn and it will automatically change in cyan?"
Yes, it will be a shared variable highglighted in cyan (just as my answer shows).
"That's what I did but nothing changed and if I run the code a warning appears telling me that it can not find any variable (referring to the line I used it in the secondary fcn)."
Then most likely you did something wrong. However because you did not show/upload the code that you tried, I cant help you debug it. Note how I provided a working example for you. Common variable name mistakes include spelling errors, different capitalization, visually similar characters, etc. You might also have declared the variable in a specific way that is not syntactically recognised as a shared variable (e.g. as an output argument, or from inside a local function). But once again, without seeing your code, we cannot help you to debug what you have done wrong.
"Is there any command line I can use to prevently create a variable as able to span multiple fcn"
I do not understand what it means to "prevently" create a variable, so your question is not clear to me.
In any case, shared variables are created by their syntactical usage, not by a command.
Fulvio Cordella
Fulvio Cordella 2021 年 7 月 2 日
Thank you for your patience. I am not able to share my code because I am not possessing the device in which I wrote it for several days. I would have posted it, indeed. Anyway, thank you, I noticed other topics in other q&a and blogs that tell your same answer so I am gonna mark it as best answer :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by