From: Philip on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <f3de2c64-eb1b-48a9-bae0-cf16bdcde839(a)q8g2000vbm.googlegroups.com>...
> Philip:
> Do you have the Image Processing Toolbox? If so, you're in luck.
> It's just one line:
>
> % Create 4 regions of sample data
> accx = [10 9 7 9 10 10 10 7 7 10 10 7 10] % accelerometer data in x
> maxaccx = 10 % maximum value of accx
> thresh = 0.8 * maxaccx % maxaccx*0.8
> % Do the thresholding.
> thresholdedData = accx > thresh
>
> % Now do what Philip wants.....
> % One single line to count the number of times
> % the signal exceeds the threshold.
> [labeledData, numberOfRegions] = bwlabel(thresholdedData)


To be honest, I wouldn't know if I had the Image Processing Toolbox or not!! But the example seemed to work for me so I'm guessing so!

Ok using this its getting the correct number of regions, but I'm getting an absolutely massive column of 0 ouputs beforehand... is there any way of hiding this?
From: Walter Roberson on
"Philip " <wibs2k(a)hotmail.com> wrote in message <ht45lc$lb2$1(a)fred.mathworks.com>...
> "Walter Roberson" <roberson(a)ibd.nrc-cnrc.gc.ca> wrote in message <ht456c$jmq$1(a)fred.mathworks.com>...

> > sum( X(1:end-1) < threshold & X(2:end) > threshold )

> And if it hits the threshold I understand what you mean because there would be an odd number of crossings.

The code I wrote depends upon immediately adjacent values being above and below the threshhold, but suppose the sequence went BTA where B is below and A is above and T is right at the threshold. My code would not detect this as a threshold. If you changed the '>' in my code to >= then it would detect it. Actually, that is not a bad solution to the problem; I was concerned about symmetry if you were counting down transitions and had used an equality on both sides, but on further thought it isn't a problem.
From: ImageAnalyst on
On May 20, 4:35 pm, "Philip " <wib...(a)hotmail.com> wrote:
> Ok using this its getting the correct number of regions, but I'm getting an absolutely massive column of 0 ouputs beforehand... is there any way of hiding this?
-------------------------------------------
Philip:
You can type ver on the command line and it will tell you what
toolboxes you have.

I purposely left off the semi-colons so that you can see the output.
Add semi-colons at the end of the lines if you want to suppress the
output that would otherwise go to the command window.

From: Philip on
Thank you all very much for your help. I believe that I have got this all sorted now using ImageAnalysts code.

Thanks again,

Philip