フィルターのクリア

How to change function coefficients?

1 回表示 (過去 30 日間)
Arseniy Sleptsov
Arseniy Sleptsov 2019 年 9 月 12 日
回答済み: Stephen23 2019 年 9 月 12 日
Assume there is a function file:
function y = myFun(x)
coef = 1;
y = coef*x^2;
end
How to change coefficient in another script when calling this function? I know that I can do myFun(coef,x), but I will have then 2 variables (more if x is vector of vars). I want to call in my main script this fubction with changed coefficients:
func = @myFun; % but with changed coef

回答 (1 件)

Stephen23
Stephen23 2019 年 9 月 12 日
Following the guidelines given in the MATLAB documentation:
You could use an anonymous function:
function y = myFun(x,coef)
y = coef*x^2;
end
and then:
func = @(x)myFun(x,1);

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by