Flipping a curve to match another in a figure
4 次查看(过去 30 天)
显示 更早的评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!