Function outputs inside another function

3 ビュー (過去 30 日間)
Dimitris K
Dimitris K 2021 年 8 月 3 日
コメント済み: Dimitris K 2021 年 8 月 3 日
Hello everyone,
I am writing a script where I call a main function to update my variables. However this function has two outputs only and inside this function i call other functions with other outputs. So the outputs of the other functions are lost from workspace when the programms finishes as they are not output of my main function...
How can i also have all these outputs remaining in my workspace so that i can use them later in my script?

採用された回答

Yongjian Feng
Yongjian Feng 2021 年 8 月 3 日
Why not extend the outputs of your main function to output those information you want?
If for some reason that you can't extend the output of your main function, there are still some options:
  1. Use global variables. Your "other" functions output to the global variables, so they can be stored.
  2. A more object-oriented approach, using singleton. Create a singleton outside your main function. Store all the information to the singleton, which will stay even after your main function returns.
  6 件のコメント
Yongjian Feng
Yongjian Feng 2021 年 8 月 3 日
Using a good naming convention is definitely a good idea.
Dimitris K
Dimitris K 2021 年 8 月 3 日
Thank you both for your answers ! They are very helpful! I think i will use a structure eventually and that was what i was thinking initially. I was just wondering if there was a more neat way, but i think this is the neatest way possible and the most straightforward to implement.
The only problem with the structure arrays is the indexing and when you are using them as input in functions!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by