# What's wrong with this expression?

1 回表示 (過去 30 日間)
massi 2015 年 4 月 1 日

Hello,
I have a vector x=[0:1:1000] and I would like to write the general expression of Gaussian(a,b,c,x) vector where a,b,c are its parameters that I can define time by time. Then I should plot it. The main problem is to write the expression
y=a*'exp(-(x-b)*'(x-b)/'(c*c))
that is in this way, not correct.. Thanks Bye Marco

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

### 回答 (2 件)

Roger Stafford 2015 年 4 月 1 日

y=a*exp(-(x-b).^2/c^2);
##### 0 件のコメント-2 件の古いコメントを表示-2 件の古いコメントを非表示

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

Adam Wyatt 2015 年 4 月 1 日
Are a, b, & c scalars. If so: y = a*exp(-((x-b)/c).^2);
However, a more general version makes use of bsxfun ( see this post ) so that it can accept variable inputs:
% Search documentation for anonymous functions
Gaussian = @(A, x0, dx, x) bsxfun(@times, A, exp(-bsxfun(@rdivide, bsxfun(@minus, x, x0), dx).^2));
Lets say you wanted to generate a Gaussian at different central positions:
x = (0:1000).'; % x is a column vector - good practise to use column vectors
x0 = [300; 500; 600]; % x0 is a column vector
y = Gaussian(1, x0.', 100, x); % y is a 2D matrix with x (the domain) down the columns, x0 along the rows
plot(x, y); % Plot three shifted Gaussians

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

### カテゴリ

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

### Community Treasure Hunt

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

Start Hunting!

Translated by