Overplotting 6 graphs by changing into 3 graphs in MATLAB

In summary, there are a total of 4 MATLAB codes and 4 separate MATLAB M-files, with 2 M-files designated for producing 3 plots and another 2 M-files for producing another 3 plots. These plots are generated using the ode solver and there are also separate M-files for containing differential equations and plotting the graphs. The goal is to overplot the 6 plots into 3 plots, with one plot containing c and c_0, another for s and s_0, and the last one for q and q_0. The time interval for these 3 plots can be between 0 to 0.2*10^-9. This can be achieved by using the 'hold on' command in conjunction
  • #1
wel
Gold Member
36
0
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:
% 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:
  % 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:
Physics news on Phys.org
  • #2
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.
 

Related to Overplotting 6 graphs by changing into 3 graphs in MATLAB

1. What is overplotting and why is it a problem when creating graphs in MATLAB?

Overplotting occurs when multiple data points are plotted on top of each other, making it difficult to distinguish individual data points and patterns. This can be a problem when creating graphs because it can lead to misinterpretation of the data and make it harder to convey the intended message.

2. How can changing 6 graphs into 3 graphs in MATLAB help with overplotting?

Changing 6 graphs into 3 graphs in MATLAB can help with overplotting by reducing the number of data points plotted on each graph. This allows for better visualization and interpretation of the data without overcrowding the graph.

3. Can overplotting be avoided without changing the number of graphs in MATLAB?

Yes, overplotting can be avoided without changing the number of graphs by using different plotting techniques such as scatter plots or line plots, adjusting the size and shape of data points, and using transparency or color coding to distinguish between data points.

4. Are there any downsides to changing 6 graphs into 3 graphs in MATLAB?

One potential downside to changing 6 graphs into 3 graphs in MATLAB is that it may result in some loss of information or detail. This could be a concern if the data is complex or if there are important patterns that may be missed by reducing the number of graphs.

5. Are there any other techniques for reducing overplotting in MATLAB?

Yes, there are other techniques for reducing overplotting in MATLAB such as using log scales, plotting data in different dimensions, or using interactive tools like zoom and pan to explore the data. It is also important to carefully select the appropriate type of graph for the data being presented.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Replies
1
Views
1K
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top