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!