Path: news.mathworks.com!not-for-mail
From: "manesh g" <manesh_g2001@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: peak position
Date: Sat, 17 Jan 2009 04:26:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 30
Message-ID: <gkrmkq$ni$1@fred.mathworks.com>
References: <gkp4i0$2au$1@fred.mathworks.com> <gkp5c5$k9a$1@fred.mathworks.com> <gkp8n2$7jk$1@fred.mathworks.com>
Reply-To: "manesh g" <manesh_g2001@yahoo.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 1232166362 754 172.30.248.35 (17 Jan 2009 04:26:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 17 Jan 2009 04:26:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1403741
Xref: news.mathworks.com comp.soft-sys.matlab:512177


Hi Matt Fig,
thanks much. It works only for a special case; the script finds the maximum x values of the plots (I mean peak positions), but in my case I have many peaks in a single data. So I want to define a x-range and wish to find the peak x-values of that range. How to modify your script to do that?
thanks,
Mane


"Matt Fig" <spamanon@yahoo.com> wrote in message <gkp8n2$7jk$1@fred.mathworks.com>...
> Sorry, I may have been unclear.  'chi' is a shortcut for 'children'.  Clear your workspace (if you can without data loss!) then paste this in the command window.  It finds the x-values of the peaks of the two lines plotted.
> 
> x = 0:.001:3;
> plot(x,cos(x-1),x,sin(x)) % Peaks at pi.2 and 1.
> ch = get(gca,'children'); % Get the children of the axes(lines).
> yd = get(ch(:),'ydata'); % The y-data.
> xd = get(ch(:),'xdata');% The x-data.
> 
> xmx = zeros(1,length(ch)); % Preallocation.
> 
> for ii = 1:length(yd)
>     [idx,idx] =  max(yd{ii}); % The index of the max val of y.
>     xmx(ii) = xd{ii}(idx); % The x value at that index.
> end
> 
> xmx % display the x-values of the peaks
> 
> 
> 
> 
> 
> 5CBw48<8HL<YRl4;GRABB6@H:;Y64GR4RB?GR`BC4R4?IR5 A>4@8RB8r;,