MATLAB: Trying to plot three sets of means into one graph/one figure

brownian motionfiguremeanplotplottingsubplotwiener process

I'm trying to plot three different Brownian motion means into one plot. I'm able to get three figures as I did that, but I'm having a hard time plotting the three lines into one graph. I tried subplot, but I think I'm doing it wrong as it isn't working.
for i = 1:100
W(:,i) = brownianPath(1,200);
l1 = mean(W,2);
figure(1);
plot(l1,'g-');
grid on
end
for p = 1:1000
W(:,p) = brownianPath(1,200);
k = mean(W,2);
figure(2);
plot(k,'r-');
grid on
end
for g = 1:10000
W(:,g) = brownianPath(1,200);
h = mean(W,2);
figure(3);
plot(h,'b-')
grid on
end

Best Answer

You open three different figures in your code. That is wrong. Instead, define one figure at the beginning and let anything plot on it.
figure;hold on;grid on;
for i = 1:100
W(:,i) = brownianPath(1,200);
l1 = mean(W,2);
plot(l1,'g-');
end
for p = 1:1000
W(:,p) = brownianPath(1,200);
k = mean(W,2);
plot(k,'r-');
end
for g = 1:10000
W(:,g) = brownianPath(1,200);
h = mean(W,2);
plot(h,'b-')
end