Shifting a graph without altering the data itself.
이전 댓글 표시
Hi, I have the following graph in which I'd like the two curves to coincide as closely as possible. Is there a way to achieve that without altering the data? Also, simply shifting the x data within the plot function by a certain offset (i.e. plot(x+offset,y)) doesn't yield the desired result.

Below is the plotting:
figure
subplot(2,1,1)
plot(k,RCS_PO,'k',k,RCS_MOM_soft,'m',k,RCS_MIE_soft,'b','LineWidth',2);
답변 (1개)
Star Strider
2016년 12월 22일
0 개 추천
댓글 수: 6
Yuval
2016년 12월 22일
Star Strider
2016년 12월 22일
It requires a bit more than that:
x = linspace(0, 4*pi);
y1 = sin(x);
y2 = cos(x);
[y1a,y2a] = alignsignals(y2, y1); % Note Order of Arguments
xa = linspace(0, 4*pi*length(y1a)/length(y1), length(y1a)); % New Independent Variable For Aligned Signal
figure(1)
subplot(2,1,1)
plot(x, y1, '-b', x, y2, '-.r')
grid
subplot(2,1,2)
plot(xa, y1a, '-b', x, y2a, '-.r')
grid
Experiment with this code snippet, and with your signals to get the result you want.
Yuval
2016년 12월 22일
Star Strider
2016년 12월 22일
I don’t know what’s wrong.
Experiment with changing the order of the arguments to alignsignals. In my experiments with it, it aligns the first argument to match the second argument.
It may not be possible to align your signals exactly. Looking at the zero-crossings, they don’t appear to have the same frequencies and phase relationships.
Yuval
2016년 12월 22일
Star Strider
2016년 12월 22일
For that, I would choose a subset of your data (for example 4 to 8 ka) and use the delay calculated from that. You would insert a zero or NaN vector the length of the delay returned as the third argument of alignsignals to your signal vector, and use linspace to extend your independent (probably time) vector to the appropriate length.
카테고리
도움말 센터 및 File Exchange에서 Transforms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!