# Thread: MatLab Help for Beginner

1. ## 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?

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

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

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

Well there are a couple of approaches to this problem, you can use the same technique as above on dd as was used on ddata, recursivly for as many times as number of samples less than the threshols as desired, or you can write a loop counting 1's in bdata.

Something like:

Code:
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
(warning untested code)

RonL