MATLAB: Problem plotting on a graph

graphsplotting

[EDIT: 20110523 16:19 CDT – merge duplicate – WDR]
I have a problem plotting something on a graph.
I have a program that runs a function, this function plots a graph. The program loops the function for different parameters. How can I make sure the output of the function is plotted on the graph next to the output from the previous loop, etc.?
This is the program code:
clear all
close all
pe_alles = 200+200*rand(10,1);
pt_alles = 80+20*rand(10,1);
ce_alles = 2547+1000*rand(10,1);
ct_alles = 450+200*rand(10,1);
for i = 1:10
pe = pe_alles(i);
pt = pt_alles(i);
ce = ce_alles(i);
ct = ct_alles(i);
Thesis_tables
end
This is the plotting end of the function:
% FIGURES
clf reset
figure (1)
hold on
plot(y1:y2,SSB,'yo')
plot(y1:y2,SSB_ITQ,'mo')
plot(y1:y2,SSB_IQ,'ro')
plot(y1:y2,SSB_0,'go')
xlabel('Year'); %time
ylabel('Spawning stock biomass (t)'); %spawning stock biomass
title('Population dynamics'); %population dynamics
figure (2)
hold on
plot(y1:y2,TY, 'y+')
plot(y1:y2,TY_ITQ, 'm+')
plot(y1:y2,TY_IQ, 'r+')
xlabel('Year)'); %time
ylabel('Catch (t)'); %Catch
title('Fishing'); %fishery
figure (5)
hold on
plot(y1:y2,P,'y')
plot(y1:y2,P_ITQ,'m')
plot(y1:y2,P_IQ,'r')
plot(y1:y2,P_ITQF,'g')
xlabel('Year');
ylabel('?');
title('Total profits') % total profits

[Material from duplicate]
Hi everyone,
I made a program that does some simple computing and comes up with 5 graphs, each with some process form the computing described on it:
clf reset
figure (1) % Plots SSB from 2003 to 2033
hold on
plot(y1:y2,SSB,'o-')
xlabel('Year'); % Time
ylabel('Spawning stock biomass (t)');
title('Population dynamics');
figure (2)
hold on % Plots CATCH from 2003 to 2033
plot(y1:y2,TY, '+-')
xlabel('Year'); % Time
ylabel('Catch (t)');
title('Fishing'); % Fishery
figure (3)
hold on % Plots profits from food herring vessels
plot(y1:y2,PE)
%plot(y1:y2,p1k)
xlabel('Year'); %year
ylabel('?'); %euros
title('Total profits from food herring fishery');
figure (4)
hold on % Plots profits from fodder herring vessels
plot(y1:y2,PT)
%plot(y1:y2,p2k)
xlabel('Year');
ylabel('?');
title('Total profits from fodder herring fishery');
figure (5)
hold on % Plots total profits
plot(y1:y2,P)
xlabel('Year');
ylabel('?');
title('Total profits') % total profits
Than I comment the parameters used in this function and make another program, that samples hundred random values (from a range) for these parameters and than the program runs for each sample.
% Monte Carlo simulation of variable parameters
clear all
close all
pe_alles = 200+200*rand(100,1);
pt_alles = 80+20*rand(100,1);
ce_alles = 2547+1000*rand(100,1);
ct_alles = 450+200*rand(100,1);
for i = 1:10000
pe = pe_alles(i);
pt = pt_alles(i);
ce = ce_alles(i);
ct = ct_alles(i);
Herring_Baltic
end
It is more or less a Monte Carlo simulation. The graphs for each process with each sample value are plotted on the first four figures but I can't get the last figure to plot all graphs.
I don't know how this can be? Does anyone see the problem?
This is the code for calculating what is plotted on that last graph:
for t = 1:y2-y1+1 % From 2003 until 2033
r = 0.05; % 5 percent discount rate
rho(t) = (1+r)^(t-1); % Discount rate in time
p1(t) = ((TY(t)*0.086)*pe)/rho(t)-((ce*194)*g)/rho(t); % Profits per ship
p2(t) = ((TY(t)*0.022)*pe)/rho(t)-((ce*75)*g)/rho(t);
p3(t) = ((TY(t)*0.014)*pe)/rho(t)-((ce*54)*g)/rho(t);
p4(t) = ((TY(t)*0.0004)*pe)/rho(t)-((ce*14)*g)/rho(t);
p5(t) = ((TY(t)*0.0008)*pt)/rho(t)-((ct*62)*g)/rho(t);
p6(t) = ((TY(t)*0.00003)*pt)/rho(t)-((ct*47)*g)/rho(t);
p7(t) = ((TY(t)*0.000007)*pt)/rho(t)-((ct*33)*g)/rho(t);
p8(t) = ((TY(t)*0.0000006)*pt)/rho(t)-((ct*18)*g)/rho(t);
pl1(t) = p1(t)*4.3; % Profits per class = profits per ship times number of
pl2(t) = p2(t)*4.7;
pl3(t) = p3(t)*4.7;
pl4(t) = p4(t)*4;
pl5(t) = p5(t)*51.3;
pl6(t) = p6(t)*51.3;
pl7(t) = p7(t)*51.3;
pl8(t) = p8(t)*50;
PE(t) = pl1(t)+pl2(t)+pl3(t)+pl4(t); % profits for food herring vessels
PT(t) = pl5(t)+pl6(t)+pl7(t)+pl8(t); % profits for fodder herring vessels
P(t) = PE(t)+PT(t); % TOTAL profits
end
I could post all the code if necessary.

Best Answer

If "hold" does not work for you, why don't you try subplot?

help subplot
doc subplot

For example:

figure();
subplot(2,2,1);
plot(y1:y2,SSB,'yo');
subplot(2,2,2);
plot(y1:y2,SSB_ITQ,'mo')
subplot(2,2,3);
plot(y1:y2,SSB_IQ,'ro')
subplot(2,2,4);
plot(y1:y2,SSB_0,'go')

Hope it helps!