# Matlab Gaussian

1. Dec 10, 2013

### Dr_Pill

Matlab rook here,

Suppose I'd want to plot the Gaussian for 10 different values for n:

Code (Text):
function gauss(c,n) = plot_gaussian.m

x=-1*c:0.1:c;
gauss(x,j)=sqrt(j./pi)*exp(-1*j.*x.^2);
for j=1:n
plot(x,y)
end

And then I'll type gauss(3,10) to plot 10 curves in the interval [-3,3]

Also, if I'd want to plot in 10 different colors, how can I manage that?

Last edited: Dec 10, 2013
2. Dec 10, 2013

### Pythagorean

You're plotting x,y but you haven't defined a y. I assume you mean to plot(x,gauss). You also use j before you define it (so I think you want the gauss(x,j)= line to be inside a loop

You can pass a third argument to plot to represent the color and shape of the line. For instance:

plot(x,gauss,'g*') would plot a green star. Look up linespecs matlab on google.

since it's a loop, you'll have to define a cell of color specs:
C = {'g*','bd','r^'}

and then call plot like
plot(x,y,C{j})

I've only put three elements in C though, so it would error if j=4

Alternatively, you could just build up gauss in the loop, then plot it:

plot(x,gauss)

and it will automatically give each gaussian its own color.