# MatLab Help for Beginner

• Jun 20th 2008, 05:46 PM
rancediddy
MatLab Help for Beginner
Hello

I'd appreciate any help or recommendations I can get for my problem.

The basic problem:

I have a large column of data and I would like to evaluate when data in the column becomes less than predetermined value (this I can do). However the second part of this requires the data to be less than the predetermined value for a specified period of time (or number of cells) or it does not get considered.

Make sense? :)

Does anyone have suggestions?

• Jun 21st 2008, 01:05 AM
CaptainBlack
Quote:

Originally Posted by rancediddy
Hello

I'd appreciate any help or recommendations I can get for my problem.

The basic problem:

I have a large column of data and I would like to evaluate when data in the column becomes less than predetermined value (this I can do). However the second part of this requires the data to be less than the predetermined value for a specified period of time (or number of cells) or it does not get considered.

Make sense? :)

Does anyone have suggestions?

There is more than one way to skin this cat but this is one way:

Code:

```--> data=rand(20,1) data = 0.5322 0.2064 0.7200 0.0361 0.1283 0.3153 0.1913 0.9270 0.4376 0.5417 0.6870 0.5197 0.4237 0.2228 0.7730 0.5879 0.9323 0.7247 0.6626 0.5490 --> bdata=data>0.25 bdata = 1 0 1 0 0 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 --> delta=bdata(1:length(bdata)-1)- bdata(2:length(bdata)) delta = 1 -1 1 0 -1 1 -1 0 0 0 0 0 1 -1 0 0 0 0 0 --> dd=(delta==0) dd = 0 0 0 1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 --> ii=[1:length(dd)]'; --> zz=nonzeros(dd.*ii) zz = 4 8 9 10 11 12 15 16 17 18 19```
The values in zz are indices into the data matrix of elements that are less than the threshold and also the next element is less than the threshold.

RonL
• Jun 22nd 2008, 03:27 PM
rancediddy
I really appreciate the help. However, I am having trouble following what you indicated.

Perhaps I should have explained myself a little better. Or maybe what you suggested does work....I just can't follow. If so I apologize in advance and will not waste more of your time!

So - in an attempt to make this a little clearer - I have a large column of data and I would like to evaluate when the data becomes less than a predetermined value(this I can do).

I believe the second part of my problem may not have been clear the last time - The second part of this requires the data to be less than the predetermined value (in your example it was greater than .25 - that's fine), however I would like to specify that there has to be, for example, 3 consecutive data points greater than the .25 criteria, for it to 'count' or be considered for further analysis.

Again.....my apologies if this is indeed what the above code does....and I will not waste your time further.

• Jun 22nd 2008, 07:55 PM
CaptainBlack
Quote:

Originally Posted by rancediddy
I really appreciate the help. However, I am having trouble following what you indicated.

Perhaps I should have explained myself a little better. Or maybe what you suggested does work....I just can't follow. If so I apologize in advance and will not waste more of your time!

So - in an attempt to make this a little clearer - I have a large column of data and I would like to evaluate when the data becomes less than a predetermined value(this I can do).

I believe the second part of my problem may not have been clear the last time - The second part of this requires the data to be less than the predetermined value (in your example it was greater than .25 - that's fine), however I would like to specify that there has to be, for example, 3 consecutive data points greater than the .25 criteria, for it to 'count' or be considered for further analysis.

Again.....my apologies if this is indeed what the above code does....and I will not waste your time further.

```ll=length(bdata); rv=[]; for idx=1:ll   if bdata(idx)==1     n1s=0;     for jdx=1 to ncross-1       if bdata(idx+jdx) ~= 1         break;       else         n1s=n1s+1;       end     end     if n1s==ncross       rv=[rv,n1s];     end   end end```