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

61 次查看(过去 30 天)
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')

采纳的回答

Image Analyst
Image Analyst 2021-6-13
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 个评论
Adam Danz
Adam Danz 2021-6-13
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');

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by