필터 지우기
필터 지우기

Flipping a curve to match another in a figure

조회 수: 3 (최근 30일)
Ashik Rahman
Ashik Rahman 2021년 4월 7일
편집: DGM 2021년 4월 7일
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