http://www.mathworks.com/matlabcentral/newsreader/view_thread/242510
MATLAB Central Newsreader  peak position
Feed for thread: peak position
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Fri, 16 Jan 2009 05:05:04 +0000
peak position
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242510#621973
manesh g
Hi all..<br>
I have 100 plots in a figure window. Each curve has a peak within x range say between 10100. The peak positions are not at the same xvalues 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. <br>
How to write such a script in matlab? The use of ginput to find the maximum x value is tedius in my case.<br>
Any help shall be highly appreciated..<br>
thank you,<br>
Mane

Fri, 16 Jan 2009 05:18:02 +0000
Re: peak position
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242510#621978
Matt Fig
Are you saying that you don't have the data, you only have the plots? You can get the data by looking in the 'xdata' and 'ydata' properties of the line objects (children of the axes). Then you can use the max function to find the peaks. For example:<br>
<br>
<br>
x = 0:.1:10;<br>
plot(x,x.^2,x,x.^2.1,x,x.^2.2) % To catch up to where you are.<br>
ch = get(gca,'chi')<br>
get(ch(:),'ydata')<br>
<br>
Now the y data is stored in a cell array.<br>
<br>
<br>
<br>
<br>
`PBBFQ`PHBNPUIgB:ZIPnWDFMU&`BPV!OUQVMOFCLzB`CPJ`I``N.gDJF`B

Fri, 16 Jan 2009 05:19:01 +0000
Re: peak position
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242510#621980
Sadik
"manesh g" <manesh_g2001@yahoo.com> wrote in message <gkp4i0$2au$1@fred.mathworks.com>...<br>
> Hi all..<br>
> I have 100 plots in a figure window. Each curve has a peak within x range say between 10100. The peak positions are not at the same xvalues 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. <br>
> How to write such a script in matlab? The use of ginput to find the maximum x value is tedius in my case.<br>
> Any help shall be highly appreciated..<br>
> thank you,<br>
> Mane<br>
<br>
Hello Mane,<br>
<br>
I will try to give you the outline and hopefully you will fill in the blanks using the help menu.<br>
<br>
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).<br>
<br>
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:<br>
<br>
currentXData = get(currentLineHandle,'XData');<br>
[maxValue,maxIndex] = max(get(currentLineHandle,'YData'));<br>
currentMaxOccursAt = currentXData(maxIndex);<br>
<br>
Hope this helps. Sorry for the very summarized explanation. You may need to spend some time.<br>
<br>
Thanks.

Fri, 16 Jan 2009 05:44:02 +0000
Re: peak position
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242510#621987
manesh g
Dear Matt Fig,<br>
thanks for the clue. I can use the data itself, but I want the xvalue, and I do not understand ur script, "chi" for example. When I tried ur script it does not work out. I am a beginner to Matlab, can you explain me the steps?<br>
thanks,<br>
manesh<br>
<br>
<br>
"Matt Fig" <spamanon@yahoo.com> wrote in message <gkp5aa$ig7$1@fred.mathworks.com>...<br>
> Are you saying that you don't have the data, you only have the plots? You can get the data by looking in the 'xdata' and 'ydata' properties of the line objects (children of the axes). Then you can use the max function to find the peaks. For example:<br>
> <br>
> <br>
> x = 0:.1:10;<br>
> plot(x,x.^2,x,x.^2.1,x,x.^2.2) % To catch up to where you are.<br>
> ch = get(gca,'chi')<br>
> get(ch(:),'ydata')<br>
> <br>
> Now the y data is stored in a cell array.<br>
> <br>
> <br>
> <br>
> <br>
> `PBBFQ`PHBNPUIgB:ZIPnWDFMU&`BPV!OUQVMOFCLzB`CPJ`I``N.gDJF`B

Fri, 16 Jan 2009 06:16:03 +0000
Re: peak position
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242510#621993
Matt Fig
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 xvalues of the peaks of the two lines plotted.<br>
<br>
x = 0:.001:3;<br>
plot(x,cos(x1),x,sin(x)) % Peaks at pi.2 and 1.<br>
ch = get(gca,'children'); % Get the children of the axes(lines).<br>
yd = get(ch(:),'ydata'); % The ydata.<br>
xd = get(ch(:),'xdata');% The xdata.<br>
<br>
xmx = zeros(1,length(ch)); % Preallocation.<br>
<br>
for ii = 1:length(yd)<br>
[idx,idx] = max(yd{ii}); % The index of the max val of y.<br>
xmx(ii) = xd{ii}(idx); % The x value at that index.<br>
end<br>
<br>
xmx % display the xvalues of the peaks<br>
<br>
<br>
<br>
<br>
<br>
5CBw48<8HL<YRl4;GRABB6@H:;Y64GR4RB?GR`BC4R4?IR5 A>4@8RB8r;,

Sat, 17 Jan 2009 04:26:02 +0000
Re: peak position
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242510#622221
manesh g
Hi Matt Fig,<br>
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 xrange and wish to find the peak xvalues of that range. How to modify your script to do that?<br>
thanks,<br>
Mane<br>
<br>
<br>
"Matt Fig" <spamanon@yahoo.com> wrote in message <gkp8n2$7jk$1@fred.mathworks.com>...<br>
> 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 xvalues of the peaks of the two lines plotted.<br>
> <br>
> x = 0:.001:3;<br>
> plot(x,cos(x1),x,sin(x)) % Peaks at pi.2 and 1.<br>
> ch = get(gca,'children'); % Get the children of the axes(lines).<br>
> yd = get(ch(:),'ydata'); % The ydata.<br>
> xd = get(ch(:),'xdata');% The xdata.<br>
> <br>
> xmx = zeros(1,length(ch)); % Preallocation.<br>
> <br>
> for ii = 1:length(yd)<br>
> [idx,idx] = max(yd{ii}); % The index of the max val of y.<br>
> xmx(ii) = xd{ii}(idx); % The x value at that index.<br>
> end<br>
> <br>
> xmx % display the xvalues of the peaks<br>
> <br>
> <br>
> <br>
> <br>
> <br>
> 5CBw48<8HL<YRl4;GRABB6@H:;Y64GR4RB?GR`BC4R4?IR5 A>4@8RB8r;,

Sat, 17 Jan 2009 05:07:02 +0000
Re: peak position
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242510#622223
Image Analyst
Mane<br>
Unlike the others, I'm assuming you have the data, because after all, you plotted them. There is a findpeaks() function in the signal processing toolkit. Also take a look at this peak finding code for MATLAB:<br>
<a href="http://billauer.co.il/peakdet.html">http://billauer.co.il/peakdet.html</a><br>
This will find the peaks and valleys of each curve, and allow you some determination as to what exactly constitutes a "peak," so that you can find just the major peaks and avoid little tiny noisy peaks on the major peaks if that's what you want to do.<br>
ImageAnalyst