Plot with a lag, Part 2
    5 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    alpedhuez
      
 le 8 Juin 2018
  
    
    
    
    
    Réponse apportée : Prajit T R
      
 le 11 Juin 2018
            "Suppose I want to have plot of lagged x and y that belong in table T. For example, I want to have a plot that the first element of T.x is paired with second element of T.y, the second element of T.x is paired with the third element of T.y, etc. Please advise."
Now I would like to generalize the question as follows:
Suppose I have x,y,z all belong in table T. I want to have a plot of x and y, and with hold on, a plot of x and z one period push ahead (for example, x in 2016 and z in 2015 are paired.)
Please advise.
1 commentaire
  Walter Roberson
      
      
 le 8 Juin 2018
				What can you use to determine which period data is in?
You mention years, which hints you might have dates. If so then what do you want to do about leap years?
Réponse acceptée
  Prajit T R
      
 le 11 Juin 2018
        Hi
Note that the length of vectors should be the same in order to apply the function 'plot'. So as you require to plot a delayed version of 'z' with 'x', the lengths should still match. Here is a sample code to help you:
x=[0 1 2 3 4 5 10 15 20];
y=[0 -1 -2 -3 -4 -5 0 5 0];
z=[0 2 3 1 4 5 6 7 5 6];
plot(x,y);
hold on;
plot(x,z(2:end));
You can populate the values 'x','y' and 'z' from the relevant table in your case, but make sure that the length of 'z' should be one more than that of 'x' or 'y'.
Hope this helps
Prajit
0 commentaires
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Logical dans Help Center et File Exchange
			
	Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


