Averaging two curves of a graph

3 views (last 30 days)
Alex Totir
Alex Totir on 7 Apr 2020
Commented: Alex Totir on 9 Apr 2020
For my project I need to find and plot the average of the curves produced by this code, then take their logarithm and plot that. I've tried to use previous answers however I'm completely new to MATLAB and have been struggling a lot, so I was wondering if anyone could please help out?
clear;
t_end=30; % time
a12=0.4; % level of toxicity
a21=0.6;
ht=0.1; % time step size
%inital conditions:
u=0.1;
v=0.5;
nh=t_end/ht;
%--------------------------------------------
t=0; k=0;
U1=zeros(nh,1);
V1=zeros(nh,1);
for j= 1:nh
U1(j)=u;
V1(j)=v;
u0=u+ht*u*(1-u-a12*v);
v0=v+ht*v*(1-v-a21*u);
u=u0;
v=v0;
t=t+ht;
k=k+1;
end;
% Defining the time
E=0:ht:t;
% plotting the profiles
figure
plot(E(2:end),U1,'b',E(2:end),V1,'r');
xlabel('Time')
ylabel('Relative Populations')
legend({'= u','= v'},'Location','southeast')
% Equations to quantify the success of invasions.
  2 Comments
dpb
dpb on 7 Apr 2020
Edited: dpb on 7 Apr 2020
So, why can't you use mean([U1 V1],2)?
Altho it would be easier to not use two variables but an array with two columns...
Alex Totir
Alex Totir on 9 Apr 2020
Thank you very much!

Sign in to comment.

Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!