How would I plot and connect two points properly?

19 Ansichten (letzte 30 Tage)
Abraham
Abraham am 10 Sep. 2023
Kommentiert: Image Analyst am 11 Sep. 2023
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

Antworten (1)

Image Analyst
Image Analyst am 10 Sep. 2023
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 Kommentare
Abraham
Abraham am 10 Sep. 2023
thank you so much this was perfect :)
Image Analyst
Image Analyst am 11 Sep. 2023
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by