フィルターのクリア

outputs from nested functions

6 ビュー (過去 30 日間)
Muazma Ali
Muazma Ali 2021 年 12 月 5 日
回答済み: Voss 2021 年 12 月 5 日
Hi
If u nest two functions within a parent function, can the second nested function make use of the output from the first nested function to compute its output variables--?
I assume the second nested function can make use of the local variables from the first nested function

回答 (1 件)

Voss
Voss 2021 年 12 月 5 日
Each nested function has its own workspace but they all 'see' variables from the parent workspace.
function parent()
x = 0;
function child_1()
y = 0;
% this function can use x (from the parent workspace) and y (local
% variable in this workspace).
end
function child_2()
% this function can use x (from the parent workspace).
% any variable called y here would be local to this workspace and
% separate from the y in child_1's workspace.
end
end
It is possible to have the second nested function make use of the output from the first nested function, either by (1) making the second function call the first function, or (2) having the first function calculate variables in the parent workspace.
If you have a more specific question or problem, post it and someone can give more pertinent advice for the particular situation you have in mind. I've found that nested functions are generally a very good and efficient way to do things in MATLAB.

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by