Borrar filtros
Borrar filtros

Regarding finding peak values from vectors; how do I find only the max value and also write this in a loop with changing string variable names?

2 visualizaciones (últimos 30 días)
Hello,
I am trying to make my life easier- I have something like 380 sets of data that I really don't want to find the peaks of by hand, so I am trying to write a bit of code to automate this process. Here is what I have so far:
C3ax= [List of x values, a 1X1600 double vector]
C3ay= [Corresponding list of y values, a 1X1600 double vector]
%(I have about 84 of these vector pairs, from (C3ax, C3ay) to (G12ax,G12ay))
[pks, loc]=findpeaks(C3ay(1:200))
[XVal]=C3ax(loc)
[XVal;PkVal]
%I am searching for peaks only in a certain range, thus the (1:200) %I realize that if I change the starting location from "1" in the above line, I also have to add that value to loc in the second line
So this returns values of ans =
51.5625 53.1250
2.5302 1.0381
Which is correct, and sort of what I want (specifically only the 51.5625 value). So here are my questions:
1) Is there a way to tell the find peaks function that I only want the highest peak? I would specifically like it to return only the 51.5625,2.5302 pair, but I don't know the values I would be looking for until I find them (i.e, I can't set the max height to look for because I don't know what it is a priori).
2)I would like to be able to run this in a loop so that it does C3a through C12a, then D3a through D12a, etc, but I am not great at doing loops with string terms- ideally I could do for n=1:12 and have the names be C'n'a, but I don't know how to write that so that Matlab understands. Any advice? I tried this:
C1x7UnbakedY=[C3ay,C4ay,C5ay,C6ay]
C1x7UnbakedX=[C3ax,C4ax,C5ax,C6ax]
MaxFreq=60;
for n=1:4;
YVal=C1x7UnbakedY(n)
XVal=C1x7UnbakedY(n)
[PkVal,loc]=findpeaks(YVal(1:(MaxFreq/0.3125)))
[XVal]=XVal(loc)
[XVal;PkVal]
end
But that just returned a number for YVal and XVal instead of bringing in the entire vector.
Eventually I would like to have all of the XVal terms averaged for each letter trial, but I don't think I am far enough along to get into that yet. Thanks for the help!!!
Kaitlin

Respuestas (1)

dpb
dpb el 26 de Jun. de 2013
1) Is there a way to tell the find peaks function that I only want the highest peak?
Sure...
[pks, loc]=findpeaks(v,'npeaks',1','sortstr','descend');
doc findpeaks
2)I would like to be able to run this in a loop so that it does C3a through C12a, then D3a through D12a, etc, but I am not great at doing loops with string terms- ideally I could do for n=1:12 and have the names be C'n'a, but I don't know how to write that so that Matlab understands. Any advice? ...
Yeah, "don't do that!" :)
Use structure named fields or just a large array and the column indices instead rather than 'poofing' variables into the workplace...
See the FAQ at...
for "more better" ways.
  8 comentarios
K
K el 27 de Jun. de 2013
Ok, found it- I will put this up with further details after I have dinner. Thanks!
dpb
dpb el 27 de Jun. de 2013
Saw ya' over on cs-sm...awaiting your response over there on starting w/ the data itself and let's see about getting it into Matlab in a more suitable form for automagic processing...after that, stuff should become "piece o'cake"... :)

Iniciar sesión para comentar.

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by