Trying to plot Gaussian with a for loop - no luck!

4 次查看(过去 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)

采纳的回答

Fangjun Jiang
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 CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by