1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Overplotting 6 graphs by changing into 3 graphs in MATLAB

  1. Jul 27, 2014 #1

    wel

    User Avatar
    Gold Member

    Two M-files one contains differential equations and another one to run and plot the graphs. since i am using ode solver, it has two files to run.

    THERE ARE 4 MATLAB CODES WITH 4 SEPARATE MATLAB M-FLIES BUT 2 M-FILES TO PRODUCE 3 PLOTS AND ANOTHER 2 M-FILES TO PRODUCE ANOTHER 3 GRAPHS. BUT I WANT TO OVERPLOTS THESE 6 PLOTS INTO 3 PLOTS ONLY.

    HERE ARE THE FIRST two M-files,
    ONE contains differential equations and another one CONTAINS plotting the graphs.
    since i am using ode solver, it has two files.

    Code (Text):
    % Creating recent original 3 ode without scaling any parameters and c.
       
          function xprime= ns(t,x)
       
          I=1200; % light intensity
           
          %values of parameters
            k_f= 6.7*10.^7;
            k_d= 6.03*10.^8;
            k_n=2.92*10.^9;
            k_p=4.94*10.^9;
            alpha =1.14437*10.^-3;
       
            %Unknown parameters
            lambda_b= 0.0087;
            lambda_r =835;
            gamma =2.74;
           
            %Pool Values
            P_C= 3 * 10.^(11);
            P_Q= 2.87 * 10.^(10);
           
         % initial conditions
          c=x(1);
          s=x(2);
          q=x(3);
       
          %Non-linear differential equations.
          % dc/dt= alpha*I + c(- k_f - k_d - k_n * s - k_p*(1-q))
          % ds/dt = lambda_b * c* P_C *(1-s)- lambda_r *(1-q)*s
          % dq/dt = (1-q)* k_p * c *(P_C / P_Q)- gamma * q
       
         xprime = zeros(3,1);    % a column vector
       
        xprime(1)= alpha*I + c*(- k_f - k_d - k_n * s - k_p*(1-q));
        xprime(2)= lambda_b *(1-s)*c* P_C  - lambda_r *(1-q)*s;
        xprime(3)=(1-q)*k_p* c*(P_C / P_Q)- gamma * q;
         
        % TO RUN the recent original odes with t= 0.2 *10^-9
       
          format bank
          close all;
          clear all;
          clc;
        epison= 10.^-9;
          %time interval
          ti=0;
          tf=0.2*epison;
          tspan=[ti tf];
       
          x0=[0.25 0.02 0.98]; %initial conditions
       
          %time interval of [0 2] with initial condition vector [0.25 0.02 0.98] at time 0.
          options= odeset('RelTol',1e-9, 'AbsTol',[1e-9 1e-9 1e-9]);
          [t,x]= ode23s(@ns,tspan,x0,options);
        dt = t(2:end)-t(1:end-1);  % number of time step size it is using
         
        %Plotting the graphs:
        plot(t(2:end), t(2:end)-t(1:end-1));   % plotting the time step size.
         title('Time steps for 3 recent original odes (c,s,q), time =0.2*10^-9 ');
        ylabel('t'), xlabel('t_n');
       
          figure
          subplot(3,1,1), plot(t,x(:,1),'r'),grid on;
          title('3 recent original odes, time =0.2*10^-9 '),ylabel('c');
       
          subplot(3,1,2), plot(t,x(:,2),'b'),grid on;
          ylabel('s');
       
          subplot(3,1,3), plot(t,x(:,3),'g'),grid on;
          ylabel('q');xlabel('Time')

     
    Another separate two M-files , ONE contains differential equations and another contains plotting the graphs. since i am using ode solver, it has two files.

    Code (Text):
      % 3 Asymptotic expansion t=0.2*10^-9 which gives tau =0.2
       
       
          function xpr= no(t,x)
            epison= 10.^-9;
          %values of parameters
            k_f= 6.7*10.^7;
            k_d= 6.03*10.^8;
            k_n=2.92*10.^9;
            k_p=4.94*10.^9;
           
            %Unknown parameters
            lambda_b= 0.0087;
           
            % scale parameters
            K_F= k_f *   epison;
            K_D= k_d *   epison;
            K_N= k_n *   epison;
            K_P= k_p *   epison;
            LAMBDA_B= lambda_b*  epison;
           
            %Pool Values
            P_C= 3 * 10.^(11);
            P_Q= 2.87 * 10.^(10);
           
         % initial conditions
          c_0=x(1);
          s_0=x(2);
          q_0=x(3);
       
          %Non-linear differential equations.
          % dc_0/dtau=  c_0*(- K_F - K_D - K_N * s_0 - K_P*(1-q_0))
          % ds_0/dtau = Lambda_B * c* P_C *(1-s_0)
          % dq_0/dtau = (1-q_0)* K_P * c_0 *(P_C / P_Q)
         
         
          % dc_0/dt=  c_0*(- K_F - K_D - K_N * s_0 - K_P*(1-q_0))
          % ds_0/dt = Lambda_B * c_0* P_C *(1-s_0)
          % dq_0/dt = (1-q_0)* K_P * c_0 *(P_C / P_Q)
       
        xpr= zeros(3,1);
       
        xpr(1)=c_0*(- K_F - K_D - K_N * s_0 - K_P*(1-q_0));
        xpr(2)= LAMBDA_B * c_0*P_C *(1-s_0);
        xpr(3)= (K_P * c_0*P_C*(1-q_0)) / P_Q;
       
        % TO RUN 3 asymptotic expansion for c_0,s_0 and q_0
       
          format bank
          close all;
          clear all;
          clc;
        epison= 10.^-9;
       
          %time interval
          ti=0;
          tf=0.2*epison;
          tspan=[ti tf];
         
          x0=[0.25 0.02 0.98]; %initial conditions
       
          %time interval of [0 2] with initial condition vector [0.25 0.02 0.98] at time 0.
          options= odeset('RelTol',1e-9, 'AbsTol',[1e-9 1e-9 1e-9]);
          [t,x]= ode23s(@no,tspan,x0,options);
        dt = t(2:end)-t(1:end-1); % number of time step size it is using
         
        %Plotting the graphs:
          plot(t(2:end), t(2:end)-t(1:end-1));   % plotting the time step size.
           title('Time steps for 3 asymptotic expansions (c_0,s_0, q_0) at tau=0.2');
          ylabel('t'), xlabel('t_n');
         
          figure
          subplot(3,1,1), plot(t,x(:,1),'r'),grid on;
          title('3 asymptotic expansion when t=0.2*epsion, tau= t/epison, so tau=0.2'),ylabel('c_0');
       
          subplot(3,1,2), plot(t,x(:,2),'b'),grid on;
          ylabel('s_0');
       
          subplot(3,1,3), plot(t,x(:,3),'g'),grid on;
          ylabel('q_0');xlabel('Time')
     
    There are 6 plots from these two separate m-files which contains 3 each graphs and there are different. Now i want to overplot 3 plots by combining 6 plots together into 3 plots. I mean one overplot containing c and c_0, another for s and s_0 and last one for q and q_0 and 3 in total.
    Time intervals of these 3 plots can be between 0 to 0.2*10-9.
    please help me. i will be very much grateful and thankful for your help.
     
    Last edited: Jul 27, 2014
  2. jcsd
  3. Jul 28, 2014 #2

    donpacino

    User Avatar
    Gold Member

    the command 'hold on' will allow you to add signals to figures that are already created

    plot(t,x)
    hold on
    plot(t,y)

    this will plot both y and x on the same graph.
    you can the hold command in conjunction with assigning set figures to certain plots, and you can achieve your goal.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Overplotting 6 graphs by changing into 3 graphs in MATLAB
  1. Matlab 3d graph (Replies: 1)

  2. Graphs in matlab (Replies: 2)

  3. Graphs in matlab (Replies: 9)

Loading...