How can I connect the upper endpoint of the red curve to the red dot while keeping the curvature nearly the same?
조회 수: 1 (최근 30일)
이전 댓글 표시
How can I connect the upper endpoint of the red curve to the red dot while keeping the curvature nearly the same?
clear all
format long
warning off
figure
set(0,'DefaultAxesFontSize',20);
load('BT_Hom(2).mat')
[~,idx] = max(x(326,:));
plot(x(326,1:idx-20),x(325,1:idx-20),'r', 'LineWidth',2);
hold on
axis([0.14 .18 .15 .18]);
scatter(0.174701,0.177614, 'o', 'MarkerFaceColor', 'r');
xlabel('$a\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$b\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
댓글 수: 0
채택된 답변
Star Strider
2024년 6월 8일
clear all
format long
warning off
figure
set(0,'DefaultAxesFontSize',20);
load('BT_Hom(2).mat')
[~,idx] = max(x(326,:));
plot(x(326,1:idx-20),x(325,1:idx-20),'r', 'LineWidth',2);
hold on
axis([0.14 .18 .15 .18]);
scatter(0.174701,0.177614, 'o', 'MarkerFaceColor', 'r');
% line_end = [x(326,idx-20),x(325,idx-20)];
line_end = [x(326,idx-21:idx-20);x(325,idx-21:idx-20)];
scatter_point = [0.174701,0.17761];
connecting_line(1,:) = linspace(line_end(1), scatter_point(1), 150);
connecting_line(2,:) = pchip([line_end(1,:) scatter_point(1)], [line_end(2,:) scatter_point(2)], connecting_line(1,:));
plot(connecting_line(1,:), connecting_line(2,:),'r', 'LineWidth',2);
title('Using ‘pchip’')
xlabel('$a\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$b\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
figure
set(0,'DefaultAxesFontSize',20);
load('BT_Hom(2).mat')
[~,idx] = max(x(326,:));
plot(x(326,1:idx-20),x(325,1:idx-20),'r', 'LineWidth',2);
hold on
axis([0.14 .18 .15 .18]);
scatter(0.174701,0.177614, 'o', 'MarkerFaceColor', 'r');
% line_end = [x(326,idx-20),x(325,idx-20)];
line_end = [x(326,idx-21:idx-20);x(325,idx-21:idx-20)];
scatter_point = [0.174701,0.17761];
connecting_line(1,:) = linspace(line_end(1), scatter_point(1), 150);
connecting_line(2,:) = makima([line_end(1,:) scatter_point(1)], [line_end(2,:) scatter_point(2)], connecting_line(1,:));
plot(connecting_line(1,:), connecting_line(2,:),'r', 'LineWidth',2);
title('Using ‘makima’')
xlabel('$a\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$b\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
figure
set(0,'DefaultAxesFontSize',20);
load('BT_Hom(2).mat')
[~,idx] = max(x(326,:));
plot(x(326,1:idx-20),x(325,1:idx-20),'r', 'LineWidth',2);
hold on
axis([0.14 .18 .15 .18]);
scatter(0.174701,0.177614, 'o', 'MarkerFaceColor', 'r');
% line_end = [x(326,idx-20),x(325,idx-20)];
line_end = [x(326,idx-21:idx-20);x(325,idx-21:idx-20)];
scatter_point = [0.174701,0.17761];
connecting_line(1,:) = linspace(line_end(1), scatter_point(1), 150);
connecting_line(2,:) = spline([line_end(1,:) scatter_point(1)], [line_end(2,:) scatter_point(2)], connecting_line(1,:));
plot(connecting_line(1,:), connecting_line(2,:),'r', 'LineWidth',2);
title('Using ‘spline’')
xlabel('$a\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$b\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
This uses the last two points of the red line so that the interpolation functions can use that slope information as well. That is straightforward to expand if necessary. The original (and now commented-out) vales for ‘line_end’ used only the last point.
Zoom in on these to see which works best for you.
.
추가 답변 (1개)
Image Analyst
2024년 6월 8일
Try using plot after you use scatter to draw a line from the last point on the curve to the marker you placed with scatter():
figure
set(0,'DefaultAxesFontSize',20);
load('BT_Hom(2).mat')
[~,idx] = max(x(326,:));
plot(x(326,1:idx-20), x(325,1:idx-20), 'r', 'LineWidth',2);
hold on
axis([0.14 .18 .15 .18]);
scatter(0.174701,0.177614, 'o', 'MarkerFaceColor', 'r');
xTip = [x(326,1:idx-20), 0.174701];
yTip = [x(325,1:idx-20), 0.177614];
plot(xTip, yTip, 'r-', 'LineWidth', 2);
grid on;
xlabel('$a\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
ylabel('$b\rightarrow$','FontSize',20,'interpreter','latex','FontWeight','normal','Color','k')
There will be a slight change in curvature. It it's really objectionable, you can use the scatter point and the last two points of the curve and fit a cubic to it and interpolate a bunch of points in between. Not sure it would look much different though than the straight line.
댓글 수: 3
Image Analyst
2024년 6월 8일
편집: Image Analyst
2024년 6월 8일
As you can see, Star used some more sophisticated methods and the plot looks virtually the same. Are they still not good enough? Is so, why not? What is the purpose of the plot? Who is the consumer/viewer of these plots and will they be annoyed if it's not smoother?
But realize that as the final point gets much further away, the connecting curve will have to look more and more like a line. I mean if the point was out at 0.4 or 0.5, what would you expect the connecting curve to look like? It can't be very curvy!
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!