Trying to plot Gaussian with a for loop - no luck!
1 次查看(过去 30 天)
显示 更早的评论
Greetings all,
I'm trying to plot a simple Gaussian curve, but nothing shows up in my figure. Should be pretty simple, right? Just my luck! Here's what I'm using:
clc
clear all
close all
%Gaussian plot
for x=-4:1:4
A = ((1)/sqrt(2*pi))*exp((-x^2)/2);
end
figure (1)
plot (A)
0 个评论
采纳的回答
Fangjun Jiang
2011-9-23
You are over-writing A every time in the for-loop so the plot just shows one data point.
Declare A as an array, and then use A(x) in the for-loop, you will get all the data for x=-4:1:4 and then you will see a curve.
Well, since your x=-4:1:4 contains negative and zero, you can not really use A(x). I think you'll find a way.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!