How can i plot a square to my graphs maximum value?

How can i plot a square to my graphs maximum value?

댓글 수: 1

Have you tried the rectangle(), plot(), line(), xlim(), or ylim() functions? I really don't have any idea of what the square should look like so please post a screenshot - mock something up in Photoshop if you have to.

댓글을 달려면 로그인하십시오.

답변 (1개)

Mike Garrity
Mike Garrity 2014년 9월 30일
Given a plot you've created using something like this:
h = plot(data);
Consider this:
y = get(h,'YData');
i = find(y==max(y));
x = get(h,'XData');
hold on
plot(x(i),y(i),'s')'
hold off
The variable Y contains the data you've plotted. The variable i will then be the index the largest value. The last three lines will add another plot which draws square markers at the locations specified by variable i. The "hold on" and "hold off" make this new plot overlay the original one instead of clearing the axes.
A couple of notes.
If Y contained multiple values which were exactly equal to the max, then i will be a vector of indices, and you'll get multiple squares. If that's a problem, just truncate i to use just the first one.
For some types of plots, you might have other data to worry about, such as ZData or CData. You'd just need to do the same thing with those. Get them from the first plot, index into them, and put them into the second plot.
Does that make sense?

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

질문:

2014년 9월 30일

답변:

2014년 9월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by