how to plot a gaussian 1D in matlab
690 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gadadhar Sahoo
am 1 Dez. 2017
Kommentiert: Chad MacDonald
am 2 Aug. 2023
for k = 1 : K
ax = linspace(min_x,max_x,100);
y = my_gaussian(x,means,vars);
plot(ax,y);
end
0 Kommentare
Akzeptierte Antwort
M
am 1 Dez. 2017
Bearbeitet: Adam Danz
am 14 Jul. 2020
You can use Matlab function to construct Gaussian function :
x = 0:0.1:10;
y = gaussmf(x,[2 5]);
plot(x,y)
4 Kommentare
Chad MacDonald
am 2 Aug. 2023
The gaussmf function evaluates a Gaussian membership function for a fuzzy logic system, which is not the same thing as a Gaussian distribution. For more information on Gaussian probability distributions, see Normal Distribution (Statistics and Machine Learning Toolbox).
Weitere Antworten (1)
Adam Danz
am 14 Jul. 2020
Bearbeitet: Adam Danz
am 14 Jun. 2022
Fully parameterized gaussian function (no toolboxes needed)
If you don't have the Fuzzy Logic toolbox (and therefore do not have access to gaussmf), here's a simple anonymous function to create a paramaterized gaussian curve.
gaus = @(x,mu,sig,amp,vo)amp*exp(-(((x-mu).^2)/(2*sig.^2)))+vo;
- x is an array of x-values.
- mu is the mean
- sig is the standard deviation
- amp is the (positive or negative)
- vo is the vertical offset from baseline (positive or negative)
To add noise along the y-axis of the guassian,
y = gaus(___);
yh = y + randn(size(y))*amp*.10; % noise is 10% of the amp
Demo
x = linspace(-5,25,100);
mu = 10;
sig = 5;
amp = 9;
vo = -5;
y = gaus(x,mu,sig,amp,vo);
% Plot gaussian
plot(x, y, 'b-', 'LineWidth',3)
% Add noise
yh = y + randn(size(y))*amp*.10;
hold on
plot(x, yh, 'ro','markersize', 4)
grid on
title(sprintf('Guassian with \\mu=%.1f \\sigma=%.1f amp=%.1f vo=%.1f', ...
mu, sig, amp, vo))
Comparison with gaussmf()
x = linspace(-15,10,100);
mu = -5.8;
sig = 2.5;
amp = 1;
vo = 0;
y = gaus(x,mu,sig,amp,vo);
% Plot gaussian from custom function
plot(x, y, 'b-', 'LineWidth',3, 'DisplayName','Custom function')
% Plot gaussian from custom function
y2 = gaussmf(x,[sig,mu]);
hold on
plot(x, y2, 'r--', 'LineWidth',4, 'DisplayName','gaussmf()')
grid on
title(sprintf('Guassian with \\mu=%.1f \\sigma=%.1f amp=%.1f vo=%.1f', ...
mu, sig, amp, vo))
legend()
1 Kommentar
Siehe auch
Kategorien
Mehr zu Fuzzy Logic Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!