How can I run a list of variables through a function to return a list of outputs?

11 ビュー (過去 30 日間)
Jacob Knight
Jacob Knight 2020 年 9 月 16 日
コメント済み: Jacob Knight 2020 年 9 月 17 日
I am trying to run
t = first_return(1,1,pf)
where pf = 1:1:10000
I would like the output t to be a list of outputs 1x10000, as if inputing a np.array in python

回答 (1 件)

madhan ravi
madhan ravi 2020 年 9 月 16 日
編集済み: madhan ravi 2020 年 9 月 16 日
Vectorise the function,
Zum Beispiel:
Output = Test(1, 1, 1 : 10) % function call
function Output = Test(x,y,z) % function definition
Output = x + y - z .^2;
end
In your case:
Pf = 1 : 10
for k = 1 : numel(Pf)
Output(k) = Test(1, 1, Pf(k)); % function call
end
function Output = Test(x,y,z) % function definition
Output = x + y - z ^ 2;
end
See the difference and why one is much better than the other.

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by