Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: peak position
Date: Fri, 16 Jan 2009 06:16:03 +0000 (UTC)
Organization: Battelle Energy Alliance (INL)
Lines: 23
Message-ID: <gkp8n2$7jk$1@fred.mathworks.com>
References: <gkp4i0$2au$1@fred.mathworks.com> <gkp5c5$k9a$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1232086563 7796 172.30.248.37 (16 Jan 2009 06:16:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 16 Jan 2009 06:16:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 688530
Xref: news.mathworks.com comp.soft-sys.matlab:511949


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;,