How to pass a parent function variable to a child function inside a for loop

12 ビュー (過去 30 日間)
Sung Han Chung
Sung Han Chung 2020 年 10 月 21 日
コメント済み: Stephen23 2020 年 10 月 21 日
Hi,
I have an inner function nested inside a for loop of a parent function. I would like to define a structure once inside the parent and have that pass through each of the nested functions inside the loop without needing to redefine the structure.
function ParentFunction(x,y,z)
MyStructure = AnotherFunction(z)
for i in 1:100
[output] = InnerFunction(MyStructure, x(i), y, z);
% do stuff with output
end
end
I need to pass MyStructure (which I only want to have to define once) through each iteration of the for loop. How can I do this?
Thanks
  1 件のコメント
Stephen23
Stephen23 2020 年 10 月 21 日
"I need to pass MyStructure (which I only want to have to define once) through each iteration of the for loop. How can I do this?"
Your code appears to already do that. Can you please explain what is does that is not working as expected.

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

採用された回答

David Hill
David Hill 2020 年 10 月 21 日
function ParentFunction(x,y,z)
for i in 1:100
[output] = InnerFunction(x(i), y, z);
% you can call AnotherFunction() here
end
end
function y = AnotherFunction(z)
end

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by