How to plot index of the coordinate on plot?
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Kalasagarreddi Kottakota
 il 10 Mar 2023
  
    
    
    
    
    Modificato: Shubham
    
 il 10 Mar 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 Commenti
Risposta accettata
  Shubham
    
 il 10 Mar 2023
        
      Modificato: Shubham
    
 il 10 Mar 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 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Axis Labels in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



