Clear Filters
Clear Filters

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

10 views (last 30 days)
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 ?

Answers (3)

Image Analyst
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

Mathieu NOE
Mathieu NOE on 3 Apr 2023
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;
% 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;
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));

Community Treasure Hunt

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

Start Hunting!