Determine the maximum with indexax function (plotyy)

1 view (last 30 days)
Hello,
I have following Problem:
First at all in my workspace I have 3 times 5696x1 double values. These datas are: time, power and distance. I plot these 3 datas with the plotyy function.
[ax,p1,p2] = plotyy (time,power,time,distance);
Now I want to determine the (y)maximum of the distance and add a text. Therefore I want to use the indexmax function but it does not describe the problem for 2 y axes.
indexmax = find(max(Y2) == Y2);
xmax=x(indexmax);
ymax=y(indexmax;
  • "Error in graph (line 8) xmax=x(indexmax);"
Thanks

Accepted Answer

Kevin
Kevin on 2 Dec 2014
Edited: Kevin on 2 Dec 2014
Thanks for your help,
Y2 ->
plotyy(X1,Y1,X2,Y2)
indexmax = find(max(Y2) == Y2);
should be:
indexmax = find(max(distance) == distance);
Nevertheless your code
[dmx,idx]=max(distance); % the distance max, location
works.
[dmx,idx]=max(Weg_mu_meter) % max. Abstand, Matrixzeile
tmx=Zeit(idx) % Zeit des maximalen Abstands
text(tmx,dmx,num2str([dmx tmx],'Max D=%.1f at %.1fsec'))
Result:
dmx =
23.5753
idx =
5130
tmx =
75.0820
I uploaded an image of the plot. The text is on the bottom right of the image. How can I put in next to the maximum?
Is it possible that dmx idx and tmx can give me out the numbers with the unit. Like s for second...
  1 Comment
dpb
dpb on 3 Dec 2014
Yes, because you didn't use the handle of the RH axes so the y value is plotted at 23.6 on the LH axes which you note is about the right vertical position on that axis. As I showed, use the handles...
hAx=plotyy(Zeit,????,Zeit,Weg_mu_meter); % don't know other variable
[dmx,idx]=max(Weg_mu_meter) % max. Abstand, Matrixzeile
tmx=Zeit(idx) % Zeit des maximalen Abstands
text(hAx(2), tmx,dmx, ...
num2str([dmx tmx],'Max D=%.1f at %.1fsec'), ...
'horizontalalignment','right', ...
'verticalalignment','bottom')
There are no inherent units associated with arrays/matrices in Matlab; you have to know what those units are and code them as shown. You can use TeX/LaTeX interpreter in text for greek for the distance as you did in the ylabel text.
Recent releases include the timeseries object/class http://www.mathworks.com/help/matlab/ref/timeseries-class.html which does have a time basis property associated with it that can be set/retrieved. Not sure precisely when introduced--I'm at R2012b which does include it (or at least an early release; I've never tried it).

Sign in to comment.

More Answers (1)

dpb
dpb on 2 Dec 2014
What's Y2???
[dmx,idx]=max(distance); % the distance max, location
tmx=time(idx); % time of max distance
text(ax(2),tmx,dmx,num2str([dmx tmx],'Max D=%.1f at %.1fsec')
Fixup format string to suit, obviously, plus may want/need to adjust location/offset to avoid clutter. See
doc text
for details.

Categories

Find more on Two y-axis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!