フィルターのクリア

Can a function inside a parent code access the full workspace of that parent code?

12 ビュー (過去 30 日間)
Anish
Anish 2013 年 7 月 30 日
I have a child function being called inside the original code. Can I have the function be able to access all of the variables (workspace) from the original code? If so, how?

採用された回答

Evan
Evan 2013 年 7 月 30 日
編集済み: Evan 2013 年 7 月 30 日
A nested function can access the variables stored in the workspace of its caller function:
function x = outer_function(a,b)
x = inner_function;
function y = inner_function
y = a + b;
end
end
>> outer_function(2,3)
ans =
5
  1 件のコメント
Walter Roberson
Walter Roberson 2013 年 7 月 30 日
Note: this strategy cannot be used to access a variable which exists in the caller function if the same variable name appears in an input or output position in the "function" declaration of the inner function.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 7 月 30 日
evalin('caller', 'who') to find the list of variables, and further evalin('caller') to get each of the values.

カテゴリ

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