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

61 vues (au cours des 30 derniers jours)
Rehanos_boyzee
Rehanos_boyzee le 12 Juin 2021
Commenté : Adam Danz le 13 Juin 2021
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 commentaires
Adam Danz
Adam Danz le 12 Juin 2021
is VarName8 a column of data?
Rehanos_boyzee
Rehanos_boyzee le 12 Juin 2021
Yes Var 8 is column of data that I'm taking importing from an excel sheet

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 13 Juin 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 commentaires
Rehanos_boyzee
Rehanos_boyzee le 13 Juin 2021
Thanks....
Adam Danz
Adam Danz le 13 Juin 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');

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by