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

10 views (last 30 days)
Idir tit on 3 Apr 2023
Commented: Mathieu NOE on 6 Apr 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 ?

Image Analyst on 3 Apr 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 on 3 Apr 2023
plot(t1,y1,t2-2,y2) for example
Idir tit on 3 Apr 2023
but i have a lot of curves

Mathieu NOE on 3 Apr 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
Mathieu NOE on 6 Apr 2023
hello
problem solved ?