Shifting a graph without altering the data itself.
Afficher commentaires plus anciens
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);
Réponses (1)
Star Strider
le 22 Déc 2016
0 votes
6 commentaires
Yuval
le 22 Déc 2016
Star Strider
le 22 Déc 2016
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
le 22 Déc 2016
Star Strider
le 22 Déc 2016
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
le 22 Déc 2016
Star Strider
le 22 Déc 2016
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.
Catégories
En savoir plus sur Transforms dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!