필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Jesse
Jesse 2011년 9월 23일
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.
  댓글 수: 1
Jesse
Jesse 2011년 9월 23일
Thanks again Fangjun! One day I'll figure this out!

댓글을 달려면 로그인하십시오.

추가 답변 (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