Flipping a curve to match another in a figure

4 views (last 30 days)
Is it possible to flip the top curve to match the other one at bottom to match the red circled area. I have attached the dataset if you want to try.

Accepted Answer

DGM
DGM on 7 Apr 2021
Edited: DGM on 7 Apr 2021
I'm not really sure what you're expecting, but you can flip it easy enough.
plot(XX,YY,'b'); hold on;
xmax=max(XXXX);
ymax=max(YYYY);
plot(xmax-XXXX,ymax-YYYY,'k');
Though I have a feeling that simple flipping isn't a good solution. Consider that the two series used to share endpoints. Perhaps it would be better to flip across a line connecting the endpoints:
Using that example:
%% using line reflection
clear; clc; clf
load('XX.mat');
load('YY.mat');
load('XXXX.mat');
load('YYYY.mat');
plot(XX,YY,'b', 'DisplayName', 'XX,YY'); hold on;
x=XXXX; % the example script uses these names
y=YYYY;
xx=[max(x) min(x)];
yy=[min(y) max(y)];
slope = (yy(2)-yy(1))/(xx(2)-xx(1))
intercept = yy(1)-xx(1)*slope
% Calculate slope and y-int of line perpendicular to reflection line
perpSlope = -1/slope;
yInt = y - perpSlope.*x;
% Find where each point (x,y) crosses the reflection line
% These should all lie on the reflection line
xintersect = (yInt-intercept)/(slope-perpSlope);
yintersect = slope*xintersect + intercept;
% Shift each (x,y) point to the origin and rotate 180 deg
% more info: http://math.sci.ccny.cuny.edu/document/show/2685
xs = x - xintersect;
ys = y - yintersect;
xr = xs * cos(pi) - ys * sin(pi);
yr = xs * sin(pi) + ys * cos(pi);
%shift back to original positions, but reflected.
xFinal = xr + xintersect;
yFinal = yr + yintersect;
% Plot the data
plot(xFinal, yFinal, 'k', 'DisplayName', 'ReflectedData')
rh = refline(slope, intercept);
rh.DisplayName = 'ReflectionLine';
legend()

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!