Path: news.mathworks.com!not-for-mail
From: "Sadik " <sadik.hava@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: peak position
Date: Fri, 16 Jan 2009 05:19:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 23
Message-ID: <gkp5c5$k9a$1@fred.mathworks.com>
References: <gkp4i0$2au$1@fred.mathworks.com>
Reply-To: "Sadik " <sadik.hava@gmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1232083141 20778 172.30.248.35 (16 Jan 2009 05:19:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 16 Jan 2009 05:19:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1666517
Xref: news.mathworks.com comp.soft-sys.matlab:511936


"manesh g" <manesh_g2001@yahoo.com> wrote in message <gkp4i0$2au$1@fred.mathworks.com>...
> Hi all..
> I have 100 plots in a figure window. Each curve has a peak within x range say between 10-100. The peak positions are not at the same x-values but all of them lie within this range. I wish to write a script which can find the peak x values of each plot (100 of them) in the graph window provided the X range is defined. 
> How to write such a script in matlab? The use of ginput to find the maximum x value is tedius in my case.
> Any help shall be highly appreciated..
> thank you,
> Mane

Hello Mane,

I will try to give you the outline and hopefully you will fill in the blanks using the help menu.

There will be 100 line objects corresponding to the 100 lines. You can find the handles to these line using the findobj function with the arguments 'Type','Line'. However, you should be careful. If you have a legend, this function should return around 300 line object handles. However, it is always easy to select one of the handles returned by findobj and change its linestyle or color to identify which one it is by for example the code set(selectedHandle,'LineWidth',5).

Once you find these handles, for each line object, there should be an XData property, giving you the range of x over which that specific line is plotted, and a YData property, giving you the values, over which you would like to find the maximum. Then the rest should be easy. Something like this [in a for loop] should work:

currentXData = get(currentLineHandle,'XData');
[maxValue,maxIndex] = max(get(currentLineHandle,'YData'));
currentMaxOccursAt = currentXData(maxIndex);

Hope this helps. Sorry for the very summarized explanation. You may need to spend some time.

Thanks.