Azzera filtri
Azzera filtri

want to display the x value of the maximum in my graph?

34 visualizzazioni (ultimi 30 giorni)
for the code below i want to display the maximum value of x on the graph can anyone please let me know thanks?
[GC,GR]=groupcounts (VarName8); % taking values from the excel sheet
area=table(GC, GR); % all areas with the number of trips to each have been totaled in this table in random order
sorted_area=sortrows(area,-1); % sorting the area and number of trips in a descending order
[Highest,index]=max(GC);
plot(GR,GC,'Linewidth',1.2,'color','b'); xlabel('Area Number'); ylabel('Total Trips');
grid on
hold on
plot(GR(index),GC(index),'r*'); text(GR(index),GC(index),'\leftarrow Maximum')
  2 Commenti
Rehanos_boyzee
Rehanos_boyzee il 12 Giu 2021
Yes Var 8 is column of data that I'm taking importing from an excel sheet

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 13 Giu 2021
Try this:
x=[1 2 3 4 5 6];
y=[5 6 7 6 5 4];
[highest,index] = max(y)
plot(x,y); text(x(index), y(index), '\leftarrow')
ylim([4, 8]);
grid on;
caption = sprintf(' maximum point at (x,y) = (%.1f, %.1f)', x(index), highest);
text(x(index), y(index), caption, 'FontSize', 12, 'Color', 'r', 'FontWeight', 'bold');
  2 Commenti
Adam Danz
Adam Danz il 13 Giu 2021
You could insert the arrow directly within the label rather than plotting the arrow and label separately and starting the label with empty space.
x=[1 2 3 4 5 6];
y=[5 6 7 6 5 4];
[highest,index] = max(y);
plot(x,y);
ylim([4, 8]);
grid on;
caption = sprintf('maximum point at (x,y) = (%.1f, %.1f)', x(index), highest);
text(x(index), y(index), [' \leftarrow ',caption], 'FontSize', 8.5, 'Color', 'r', 'FontWeight', 'bold');

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Develop Apps Using App Designer 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!

Translated by