How to shift a curve to superimpose it with another one on the same figure ?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 ?

0 Kommentare
Antworten (3)
Image Analyst
am 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:
0 Kommentare
Mathieu NOE
am 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
1 Kommentar
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

