How to shift a curve to superimpose it with another one on the same figure ?

7 vues (au cours des 30 derniers jours)
Idir tit
Idir tit le 3 Avr 2023
Commenté : Mathieu NOE le 6 Avr 2023
How to shift a curve to superimpose it with another one on the same figure, for example here I want to shift the black curve to superimpose it with the red curve ?

Réponses (3)

Image Analyst
Image Analyst le 3 Avr 2023
Maybe try rescaling the black to match the red
blackx = rescale(blackx, min(redx), max(redx));
blacky = rescale(blacky, min(redy), max(redy));
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

Alexander
Alexander le 3 Avr 2023
plot(t1,y1,t2-2,y2) for example

Mathieu NOE
Mathieu NOE le 3 Avr 2023
hello
a simple demo below you can easily adapt to your data (not provided)
x = 0:0.01:0.86;
y1 = 1./cos(x+0.25)+0.01*rand(size(x));
y2 = 1./cos(x)+0.01*rand(size(x));
y1(y1>max(y2)) = NaN;
figure(1),
plot(x,y1,'r',x,y2,'k');
% find crossing points at y threshold = 1.3
threshold = 0.75*max(y2);
[xc1] = find_zc(x,y1,threshold);
[xc2] = find_zc(x,y2,threshold);
% x distance
xd = xc1-xc2;
x1 = x;
x2 = x+xd;
figure(2),
plot(x1,y1,'r',x2,y2,'k');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Zx] = find_zc(x,y,threshold)
% positive slope "zero" crossing detection, using linear interpolation
y = y - threshold;
zci = @(data) find(diff(sign(data))>0); %define function: returns indices of +ZCs
ix=zci(y); %find indices of + zero crossings of x
ZeroX = @(x0,y0,x1,y1) x0 - (y0.*(x0 - x1))./(y0 - y1); % Interpolated x value for Zero-Crossing
Zx = ZeroX(x(ix),y(ix),x(ix+1),y(ix+1));
end

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by