How can I connect the upper endpoint of the red curve to the red dot while keeping the curvature nearly the same?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Atom
am 8 Jun. 2024
Kommentiert: Star Strider
am 10 Jun. 2024
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 Kommentare
Akzeptierte Antwort
Star Strider
am 8 Jun. 2024
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.
.
2 Kommentare
Weitere Antworten (1)
Image Analyst
am 8 Jun. 2024
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 Kommentare
Image Analyst
am 8 Jun. 2024
Bearbeitet: Image Analyst
am 8 Jun. 2024
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!
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



