Flipping a curve to match another in a figure

2 次查看(过去 30 天)
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.

采纳的回答

DGM
DGM 2021-4-7
编辑:DGM 2021-4-7
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()

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by