MATLAB Answers

How to shift my Data in X Direction?

21 views (last 30 days)
Khalil Gabsi
Khalil Gabsi on 10 Mar 2019
Answered: Munish Raj on 19 Mar 2019
Dear community,
i have a question concerning interpolation. I have some curves looking like this:
What i want to do now, ist to "shift" my Data, so that every maximum of the curve has the same X-Coordinate. I think that i should use the interp1 function? But i can´t solve it. What i´ve done so far:
[M4,IX4]=max(fid4_X_average); %to get the coordinate of the maximum value
[sizeX, Y]=size(fid1_X_average);
fid2_X_average=interp1(fid1_time-IX2 ,fid2_X_average, (0:1:sizeX));
But then i get something like that GREEN LINE (i don´t get the whole range of data i had before):
So my maximum value is now at point zero, thats ok, but why has the data before zero been cut?
  1 Comment
Khalil Gabsi
Khalil Gabsi on 10 Mar 2019
in addition:
to plot my data with an according x-value vector, is no solution for me (because of further use).
But theoretically i can use this functions and my data is plotted like i want:
plot(fid1_time-IX1, fid1_X_average)
plot(fid1_time-IX2, fid2_X_average)
plot(fid1_time-IX3, fid3_X_average)
plot(fid1_time-IX4, fid4_X_average)

Sign in to comment.

Answers (1)

Munish Raj
Munish Raj on 19 Mar 2019
Hello Khalil,
It makes sense that you can not efficienlty use interp1 to shift the maximum's as all of these waveforms have a different time axis.
If you really want to manually shift the data, you'll have to write an algorithm which shifts the waveforms by that much.
(However, you will lose data by this approach)
A sample code to shift teh waveform would be
Assuming you want to shift all the maximum's to 50,
s = zeros(size(x));
if shift >0
s(shift+1:end) = x(1:end-shift);
elseif shift <0
s(1:end+shift) = x(-shift+1:end);




Community Treasure Hunt

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

Start Hunting!

Translated by