フィルターのクリア

How to call a function from another file?

74 ビュー (過去 30 日間)
Honey Adams
Honey Adams 2019 年 1 月 5 日
コメント済み: Honey Adams 2019 年 1 月 5 日
How do i obtain results of a function I created by calling it from another script file.
function [] = mychaos(Initial_Value)
x=Initial_Value;
a=3.9;
x=a*x*(1-x)
end
My call function is shown below.I would like to pass the x=0.4 to the function above and obatin a new x value.The new x value should be able to override the old x value used.How do I go about it with wrapping the x=a*x*(1-x) in a for loop?
x=0.4
for i= 1:20 ;
mychaos(x)
end

採用された回答

Stephan
Stephan 2019 年 1 月 5 日
編集済み: Stephan 2019 年 1 月 5 日
Hi,
change your function to:
function x = mychaos(Initial_Value)
x=Initial_Value;
a=3.9;
x=a*x*(1-x);
end
and your call of the function:
x=0.4
for i= 1:20 ;
x=mychaos(x)
end
This overwrites x twenty times with the result of your function, calculated using the actual value of x.
Best regards
Stephan
  1 件のコメント
Honey Adams
Honey Adams 2019 年 1 月 5 日
Thank you.I fiigured it out earleir on my own thats why i just accepted the frrst answer.I did it the exact same way as you described.Thanks once again.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by