How to plot index of the coordinate on plot?
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kalasagarreddi Kottakota
el 10 de Mzo. de 2023
x, y are coordinates and I need also the index of the coordinate. As I have 10 coordinates , I need to have the coordinate number on the plot from 1 to 10.
clear all; close all;
x = linspace(1,10,10);
y=linspace(5,20,10);
plot(x,y,'o')
0 comentarios
Respuesta aceptada
Shubham
el 10 de Mzo. de 2023
Editada: Shubham
el 10 de Mzo. de 2023
To label each point on the plot with its index number, you can use a for loop to iterate over each coordinate and use the text () function to add the corresponding index number as a label to the plot.
Here's the modified code:
clear all; close all;
x = linspace(1,10,10);
y = linspace(5,20,10);
plot(x, y, 'o')
% add index labels to the plot
for i = 1:length(x)
text(x(i), y(i), num2str(i), 'HorizontalAlignment', 'center')
end
This code should create a plot with each point labeled with its index number, from 1 to 10. The text() function takes the x and y coordinates of the point to label, the label text (which is the index number converted to a string using `num2str()`, and an optional parameter to specify the horizontal alignment of the label (in this case, centered). The loop iterates over each coordinate, adding the corresponding index label to the plot.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!