How would I plot and connect two points properly?

19 次查看(过去 30 天)
I have a total of 4 numeric input boxes. The first two label x1 and y2 and the second two label x2 and y2. I am able to plot both coordinates on my graph, but I cant seem to be able to connect them with a line. Also when i plot them they do not plot to scale. Meaning I have to scroll through my graph in order to find the two coordinates. For example if i plot my x1 and x2 as (3,6) and my x2 and y2 as (4,7) i can only see my x1 and y1 coordinate and i would have to scroll to find my x2 and y2 because my x and y values would go by decimal increments(3.1,3.2,3.3,3.4....).
This is my code:
function PlotButtonPushed(app, event)
x=app.X1EditField.Value;
y=app.Y1EditField.Value;
a=app.X2EditField.Value;
b=app.Y2EditField.Value;
hold(app.UIAxes,"on");
plot(app.UIAxes, x, y,'mo--');
plot(app.UIAxes, a, b, 'md');
end
end

回答(1 个)

Image Analyst
Image Analyst 2023-9-10
Instead of those two plot calls, do it this way.
x=1;
y=3;
a=2;
b=1;
plot([x, a], [y, b], 'm-d', 'LineWidth', 2, 'MarkerSize', 15);
grid on;
  2 个评论
Image Analyst
Image Analyst 2023-9-11
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by