Thread Subject:
Need help incorporating "findpeaks" into a for loop with data in an array

Subject: Need help incorporating "findpeaks" into a for loop with data in an array

From: K

Date: 27 Jun, 2013 05:08:08

Message: 1 of 6

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

Subject: Need help incorporating "findpeaks" into a for loop with data

From: dpb

Date: 27 Jun, 2013 11:01:03

Message: 2 of 6

On 6/27/2013 12:08 AM, K wrote:
...

>
> 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.

OK, Kaitlin, we're here on cs-sm...

Now, as I suggested, let's start w/ the data itself and how you have it
_before_ you bring it into Matlab...the purpose being to build a storage
mechanism that will allow the automagic manipulation of it w/o the
manual renaming...

--

Subject: Need help incorporating "findpeaks" into a for loop with data

From: K

Date: 27 Jun, 2013 13:59:21

Message: 3 of 6

Good morning,

The data is in .svd format, and I run a processing program on it to convert the .svd files to .mat files containing the information I want with essentially the same names as I took the data with. I don't know what specifically you would like to know about it- the data is what it is, I am not sure what I could do differently to bring it in and still retain the information about what cables it pertains to. Thanks!

Subject: Need help incorporating "findpeaks" into a for loop with data

From: K

Date: 27 Jun, 2013 14:34:12

Message: 4 of 6

This is the Matlab file that I use to get the data in .mat form. There is another processing step with a "Runtime Engine" before this that sorts all of the domain and channel names so that this program recognizes them. Does that help?

fnames = dir(fullfile(fplace,'*svd'));

for ii = 1:length(fnames)
    clear xx yy usd
fname=fullfile(fplace,fnames(ii).name)

[xx.vibe yy.vibe usd.vibe]=GetPointData(fname,'FFT','Vib','Velocity','Magnitude',0,0);

eval(['save ' fnames(ii).name(1:end-4) '_matlab xx yy usd fname xyz']);

end

Subject: Need help incorporating "findpeaks" into a for loop with data

From: dpb

Date: 27 Jun, 2013 16:35:58

Message: 5 of 6

On 6/27/2013 9:34 AM, K wrote:
> This is the Matlab file that I use to get the data in .mat form. There
> is another processing step with a "Runtime Engine" before this that
> sorts all of the domain and channel names so that this program
> recognizes them. Does that help?
> fnames = dir(fullfile(fplace,'*svd'));
>
> for ii = 1:length(fnames)
> clear xx yy usd
> fname=fullfile(fplace,fnames(ii).name)
> [xx.vibe yy.vibe
> usd.vibe]=GetPointData(fname,'FFT','Vib','Velocity','Magnitude',0,0);
> eval(['save ' fnames(ii).name(1:end-4) '_matlab xx yy usd fname xyz']);
> end

Aha! I shoulda' known--the evil eval() reared it's ugly head! :)

OK, do me one more favor--cut the number down to say 4 or 5 instead of
length(fnames) and to save me some effort in trying to decipher the
above run the following code snippet and paste back the result...


for ii = 1:5
   clear xx yy usd
   fname=fullfile(fplace,fnames(ii).name)
   disp([fnames(ii).name(1:end-4) '_matlab xx yy usd fname xyz']);
end

This will just display the string passed to EVAL for the SAVE which will
show me precisely how the .mat files were created. That will give me
the info to look into reading them to process as desired.

Altho it strikes me as why can't/don't you just use the xx, yy, and usd
structures after loading them w/ GetPointData? You know which is what
from the file names for keeping track of what case is which, right?

--

Subject: Need help incorporating "findpeaks" into a for loop with data

From: K

Date: 1 Jul, 2013 15:12:11

Message: 6 of 6

Hi,

Thanks so much for the help, but I had to get that set finished by this week, so I have to move on from this project now. I will keep the comments about avoiding eval in mind and can look into it further if I come back to this. Thanks!!!

Kaitlin

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
findpeaks K 27 Jun, 2013 05:09:12
for loop K 27 Jun, 2013 05:09:12
data K 27 Jun, 2013 05:09:12
vector K 27 Jun, 2013 05:09:12
array K 27 Jun, 2013 05:09:12
rssFeed for this Thread

Contact us