How to name point on plot?

26 Ansichten (letzte 30 Tage)
Federico MegaMan
Federico MegaMan am 2 Dez. 2019
Bearbeitet: DGM am 13 Nov. 2024
Hello, I have to plot some points in a graphic. I know that I can mark the points with 'o' or with 'x', but can I rename the points that I plot? For example A1, A2 ecc.
This is my program and how I plot my points.
clear all
close all
clc
a1=1;
b1=1;
a2=2;
b2=0.5;
a3=3;
b3=1.5;
a4=2;
b4=2;
p0=2.1;
q0=0.6;
r0=1.5;
p1=2;
q1=2;
sol(:) = fsolve(@(x)funzmia6(x), 1:8);
s0=sol(1);
r1=sol(2);
s1=sol(3);
vxp0=[p0,p1];
vyq0=[q0,q1];
vxr0=[r0,r1];
vys0=[s0,s1];
vxpr=[p1,r1];
vyqs=[q1,s1];
vx00=[p0,r0];
vy00=[q0,s0];
figure;
hold on
plot(p0,q0,'o')
plot(p1,q1,'o')
plot(r0,s0,'o')
plot(r1,s1,'o')
plot(vxp0,vyq0)
plot(vxr0,vys0)
plot(vxpr,vyqs)
plot(vx00,vy00)
plot(a1,b1,'x')
plot(a2,b2,'x')
plot(a3,b3,'x')
plot(a4,b4,'x')
grid on
function F=funzmia6(x)
s0=x(1);
r1=x(2);
s1=x(3);
theta12=x(4);
theta13=x(5);
theta14=x(6);
L2=x(7);
L4=x(8);
a1=1;
b1=1;
a2=2;
b2=0.5;
a3=3;
b3=1.5;
a4=2;
b4=2;
p0=2.1;
q0=0.6;
r0=1.5;
p1=2.184;
q1=2.184;
F(1)=p1*p0+q1*q0-a2*p0-b2*q0-a1*p1-b1*q1+(a1^2+b1^2+a2^2+b2^2)/2+cos(theta12)*(-p0*p1-q0*q1+a1*p0+b1*q0-a1*a2-b1*b2+a2*p1+b2*q1)+sin(theta12)*(p1*q1-q0*p1-b1*p0+a1*q0+a2*b1-a1*b2+b2*p1-a2*q1);
F(2)=p1*p0+q1*q0-a3*p0-b3*q0-a1*p1-b1*q1+(a1^2+b1^2+a3^2+b3^2)/2+cos(theta13)*(-p0*p1-q0*q1+a1*p0+b1*q0-a1*a3-b1*b3+a3*p1+b3*q1)+sin(theta13)*(p1*q1-q0*p1-b1*p0+a1*q0+a3*b1-a1*b3+b3*p1-a3*q1);
F(3)=p1*p0+q1*q0-a4*p0-b4*q0-a1*p1-b1*q1+(a1^2+b1^2+a4^2+b4^2)/2+cos(theta14)*(-p0*p1-q0*q1+a1*p0+b1*q0-a1*a4-b1*b4+a4*p1+b4*q1)+sin(theta14)*(p1*q1-q0*p1-b1*p0+a1*q0+a4*b1-a1*b4+b4*p1-a4*q1);
F(4)=r1*r0+s1*s0-a2*r0-b2*s0-a1*r1-b1*s1+(a1^2+b1^2+a2^2+b2^2)/2+cos(theta12)*(-r0*r1-s0*s1+a1*r0+b1*s0-a1*a2-b1*b2+a2*r1+b2*s1)+sin(theta12)*(r1*s1-s0*r1-b1*r0+a1*s0+a2*b1-a1*b2+b2*r1-a2*s1);
F(5)=r1*r0+s1*s0-a3*r0-b3*s0-a1*r1-b1*s1+(a1^2+b1^2+a3^2+b3^2)/2+cos(theta13)*(-r0*r1-s0*s1+a1*r0+b1*s0-a1*a3-b1*b3+a3*r1+b3*s1)+sin(theta13)*(r1*s1-s0*r1-b1*r0+a1*s0+a3*b1-a1*b3+b3*r1-a3*s1);
F(6)=r1*r0+s1*s0-a4*r0-b4*s0-a1*r1-b1*s1+(a1^2+b1^2+a4^2+b4^2)/2+cos(theta14)*(-r0*r1-s0*s1+a1*r0+b1*s0-a1*a4-b1*b4+a4*r1+b4*s1)+sin(theta14)*(r1*s1-s0*r1-b1*r0+a1*s0+a4*b1-a1*b4+b4*r1-a4*s1);
F(7)=(p1-p0)^2+(q1-q0)^2 -L2^2;
F(8)=(r1-r0)^2+(s1-s0)^2 -L4^2;
end

Akzeptierte Antwort

KALYAN ACHARJYA
KALYAN ACHARJYA am 2 Dez. 2019
Bearbeitet: KALYAN ACHARJYA am 2 Dez. 2019
text(x,y,txt)
x,y represent the data point, see detail here
  3 Kommentare
Yashita
Yashita am 13 Nov. 2024
I tried doing this but this makes the label of the point appear at a random location, how do i make it so that is visible right beside the point i want to name?
DGM
DGM am 13 Nov. 2024
Bearbeitet: DGM am 13 Nov. 2024
You need to specify the location and configure it to be aligned however you want it aligned..
% some fake data and a plot
xv = linspace(0,1,20);
yv = xv.^1; % change the exponent and watch the text follow
plot(xv,yv,'-o')
% place text next to point #3 using defaults
ht(1) = text(xv(3),yv(3),'Billy');
% place text next to point #5, but change the horizontal alignment
ht(2) = text(xv(5),yv(5),'Bobby','horizontalalignment','right');
% place text next to point #7, but change the rotation
ht(3) = text(xv(7),yv(7),'Larry','rotation',-45);
% place text next to point #9, but change the vertical alignment
ht(4) = text(xv(9),yv(9),'Moe','verticalalignment','top');
% place text next to point #11, but change the alignment and add an extra offset
ht(5) = text(xv(11),yv(11),'Curly','verticalalignment','top');
ht(5).Position(1:2) = ht(5).Position(1:2) + [0.01 -0.01]; % shift SE
See also:
... and possibly:

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by