Azzera filtri
Azzera filtri

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

4 visualizzazioni (ultimi 30 giorni)
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)

Risposta accettata

Fangjun Jiang
Fangjun Jiang il 23 Set 2011
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.

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by