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

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

1 Comment

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.

Sign in to comment.

Answers (1)

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?

Categories

Tags

Asked:

on 30 Sep 2014

Answered:

on 30 Sep 2014

Community Treasure Hunt

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

Start Hunting!