フィルターのクリア

How to return the variable of a script?

23 ビュー (過去 30 日間)
sc
sc 2021 年 11 月 8 日
回答済み: Walter Roberson 2021 年 11 月 8 日
Good morning!
I have two scripts and I would like to call the variable present in one script to the other one. How can I do this with Matlab?
Thank you so much!!

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 11 月 8 日
When you execute a script, it affects the workspace of any currently executing function; if no function is currently executing then the script affects the "base" workspace.
Variables do not "belong" to scripts; variables live in the workspaces.
You cannot ask that only a certain variable in a script be calculated: you can only ask that the entire script be calculated, after which any variables it created or changed would be in the appropriate workspace. So if script A needs a variable from script B, then A can execute B and then the variable will be in the current workspace.
Scripts are different than functions. There is no way to get at a variable that lives inside another function's workspace -- not without the cooperation of the function.

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by