On Thursday, June 27, 2013 10:38:08 AM UTC+5:30, K wrote: > Hello, > > > > I am trying to incorporate the findpeaks function into a for loop to find the values at which the peaks occur for about 384 sets of data. The data sets are Matlab row vectors of 1X1600, where "C3ax" is the 1X1600 x value vector, and "C3ay" is the corresponding 1X1600 y value vector. Data sets run from A to G and 1 to 21 (So A1ax, A1ay is the first pair and G21ax,G21ay is the last pair). > > > > I am having trouble incorporating the following lines of code into a for loop: > > > > [PkVal,loc]=findpeaks(C3ay(216:426),'sortstr','descend'); > > [XVal]=C3ax(216+loc-1); > > Result=[XVal(1);PkVal(1)] > > > > The first line finds the peak values of the data set C3ay between the 216th and 426th entries. The second line gives the corresponding X value for that peak, and the third line prints the only one I am interested in, the highest value. > > > > It is easy for me to put the data sets into an array like this: > > CAllx=[C1ax,C2ax,C3ax] (etc) > > CAlly=[C1ay,C2ay,C3ay] > > > > which then gives me a 3 row, 1600 column array. I would now like to use a for loop to run the findpeaks commands and get the results in a big array, kind of like this: > > > > for n=1:3 > > [PkVal,loc]=findpeaks(CAllx(n,(216:426),'sortstr','descend'); > > [XVal]=CAlly(216+loc(n)-1); > > Result(n)=[XVal(1);PkVal(1)] > > > > So my problems are: > > 1) How do I add indices to the [PkVal,loc] part so that I stop getting matrix dimension errors? I think it needs to be something like [PkVal(n,:),loc(n,:)], but that didn't work. > > > > 2) I only want the first value from the findpeaks function, but since I have Matlab 2010 and not 2012, the 'npeaks' modifier doesn't work in conjunction with the sorting, so I need to clean that up a bit. I did realize that I think my work computer might have the 2012 version, so I will check that tomorrow. > > > > Any other suggestions you have to make this loop would be GREATLY appreciated. Changing "C'n'ax" to "C'n+1'ax" over and over is getting really old... I need help figuring out how to manipulate my giant data matrix. > > > > Thank you!!! > > Kaitlin
extrema(x) EXTREMA Gets the global extrema points from a time series.
extrema2(xy,varargin) EXTREMA2 Gets the extrema points from a surface.