How to shift my Data in X Direction?

조회 수: 77 (최근 30일)
Khalil Gabsi
Khalil Gabsi 2019년 3월 10일
답변: Munish Raj 2019년 3월 19일
Dear community,
i have a question concerning interpolation. I have some curves looking like this:
unshiftedCurves.jpg
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:
[M1,IX1]=max(fid1_X_average);
[M2,IX2]=max(fid2_X_average);
[M3,IX3]=max(fid3_X_average);
[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):
shiftedCurves.jpg
So my maximum value is now at point zero, thats ok, but why has the data before zero been cut?
  댓글 수: 1
Khalil Gabsi
Khalil Gabsi 2019년 3월 10일
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)
shiftedCurves2.jpg

댓글을 달려면 로그인하십시오.

답변 (1개)

Munish Raj
Munish Raj 2019년 3월 19일
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,
[max,idx]=max(x);
s = zeros(size(x));
shift=max-50;
if shift >0
s(shift+1:end) = x(1:end-shift);
elseif shift <0
s(1:end+shift) = x(-shift+1:end);
end

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by