フィルターのクリア

Two functions, how to read parameters created in one function in another function?

1 回表示 (過去 30 日間)
Bartosz Bagrowski
Bartosz Bagrowski 2022 年 5 月 2 日
回答済み: David Hill 2022 年 5 月 2 日
Hey,
I wanted to create two functions:
function model = CreateModel()
p1 = 1;
p1 = p1*30;
p2 = 50;
P = [p1 p2];
model.P = P;
end
and the second one:
function sol = CreateRandModel(model)
P = model.P;
HI = P(2);
sol.HI = HI;
end
They are in the separated mfiles with the names: CreateModel.m and CreateRandModel.m.
I have the problem that in function CreateRandModel I get a following error :
'Not enough input arguments.
Error in CreateRandModel (line 2)
P = model2.P;'
It looks like the second function doesn't see the first one. Could you help me to solve it?

回答 (1 件)

David Hill
David Hill 2022 年 5 月 2 日
Works fine
p=CreateModel;
s=CreateRandModel(p);

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by