Shift Plot Data Along X Axis Matlab

12.9k views Asked by At

I cannot get Matlab to plot a a second time series to specific points along the x axis. My data are two time series. Time series A is a 5 X 1 and time series B is a 7 X 1. I need A to plot on xticklabels 1-5. Then, with 'hold on', I need time series B to be shifted to the right to plot on xticklabels 6:12. I keep getting the second plot to plot directly over the first plot without the shift occurring. I've tried among other things -->

set(gca,'XTick',[6 7 8 9 10 11 12]);

and it displays x axis numbers shifting but the data does not plot in positions 6:12. Any help is much appreciated. I've seen some online answers but can't seem to get it correct.

1

There are 1 answers

0
Pieter12345 On BEST ANSWER

In Matlab, you can plot something using plot(xArray, yArray);. If you want to shift the plot along the x axis, you could use plot(xArray + amountToShift, yArray);.

As I believe shifting is not what your real problem is, I've added an example where data gets plotted in the way you described:

A = [1, 2, 2, 1, 3];
tA = 1:5;
B = [3, 5, 2, 1, 2, 7, 5];
tB = 6:12;

plot(tA, A);
hold on;
plot(tB, B);