how to use anonymous functions

How do I use an anonymous function
I've set the following:
x = 1:100
a = [1,5,2.5]
gau = @(x)@(x)(a(1).*exp(-0.5.*((x-a(2)).^2./a(3).^2)))
this works fine. but now I want to pass the 'a' parameters, so tried
c = @(g) (@(x),a), but this does not work
Ideas?

回答 (2 件)

Jeff Miller
Jeff Miller 2018 年 2 月 23 日

1 投票

x = 1:100;
a = [1,5,2.5];
gau = @(x,a)(a(1).*exp(-0.5.*((x-a(2)).^2./a(3).^2)));
m1 = gau(x,a)
Derrick Salmon
Derrick Salmon 2018 年 2 月 23 日

0 投票

Ahh - works perfectly - thanks for the help

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

質問済み:

2018 年 2 月 23 日

回答済み:

2018 年 2 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by