# Thread Subject: How to find x > threshold value for a fixed consecutive days?

 Subject: How to find x > threshold value for a fixed consecutive days? From: Karren Date: 6 Aug, 2012 09:54:11 Message: 1 of 7 Hi, Kindly assist the following: I would like to find a series of x >= 130 for a minimum 3 consecutive days. data = [126 122 130 136 112 135 138 145 109 120 119 131 180 155 130] Given data, the answer should be 135, 138 and 145 for the first series and 131 180 155 and 130 for the second series. I only know how to use the find function to figure out the threshold value but not the second condition. Really looking forward for suggestions to set up the code. Thanks very much.
 Subject: How to find x > threshold value for a fixed consecutive days? From: Bruno Luong Date: 6 Aug, 2012 11:05:16 Message: 2 of 7 data = [126 122 130 136 112 135 138 145 109 120 119 131 180 155 130] i=diff([0 data>=130 0]); i1=find(i==1); i9=find(i==-1); l=(i9-i1); b=l>=3; i1=i1(b); i9=i9(b)-1; c=arrayfun(@(i1,i9) data(i1:i9), i1, i9, 'unif', 0); c{:} % Bruno
 Subject: How to find x > threshold value for a fixed consecutive days? From: ImageAnalyst Date: 8 Aug, 2012 23:24:59 Message: 3 of 7 Karren, you can get this in one single line of code if you have the Image Processing Toolbox: % Generate some sample data. data = [126 122 130 136 112 135 138 145 109 120 119 131 180 155 130] % Get all regions >= 130 that bigger than 3 elements. measurements = regionprops(bwareaopen(data>=130, 3), data, 'PixelValues'); % All done. Now, print them out. for k = 1 : length(measurements) measurements(k).PixelValues end
 Subject: How to find x > threshold value for a fixed consecutive days? From: Karren Date: 14 Aug, 2012 00:15:12 Message: 4 of 7 "Bruno Luong" wrote in message ... > data = [126 122 130 136 112 135 138 145 109 120 119 131 180 155 130] > > i=diff([0 data>=130 0]); > i1=find(i==1); > i9=find(i==-1); > l=(i9-i1); > b=l>=3; > i1=i1(b); > i9=i9(b)-1; > c=arrayfun(@(i1,i9) data(i1:i9), i1, i9, 'unif', 0); > > c{:} > > % Bruno Thanks Bruno... The code provided really helps. But I still have one more question. Can I write the output c{:} to excel? I tried a couple times but I didn't get it. Kindly advise! Karren
 Subject: How to find x > threshold value for a fixed consecutive days? From: Karren Date: 14 Aug, 2012 00:17:10 Message: 5 of 7 ImageAnalyst wrote in message <5f0420d6-c0f3-4488-b273-8fce83218279@googlegroups.com>... > Karren, you can get this in one single line of code if you have the Image Processing Toolbox: > > % Generate some sample data. > data = [126 122 130 136 112 135 138 145 109 120 119 131 180 155 130] > > % Get all regions >= 130 that bigger than 3 elements. > measurements = regionprops(bwareaopen(data>=130, 3), data, 'PixelValues'); > > % All done. Now, print them out. > for k = 1 : length(measurements) > measurements(k).PixelValues > end > Hi, > No.. I do not have the Image Processing Toolbox. Anyway, thanks very much for the suggestion. Karren
 Subject: How to find x > threshold value for a fixed consecutive days? From: Karren Date: 14 Aug, 2012 02:15:15 Message: 6 of 7 "Bruno Luong" wrote in message ... > data = [126 122 130 136 112 135 138 145 109 120 119 131 180 155 130] > > i=diff([0 data>=130 0]); > i1=find(i==1); > i9=find(i==-1); > l=(i9-i1); > b=l>=3; > i1=i1(b); > i9=i9(b)-1; > c=arrayfun(@(i1,i9) data(i1:i9), i1, i9, 'unif', 0); > > c{:} > > % Bruno Hi Bruno, What if I only need the first (and subsequent) output(s) starting from the 3rd consecutive number that exceed 130? For this case, the answer should be ans = 145 ans = 155 and 130 Thanks very much for helping. Karren
 Subject: How to find x > threshold value for a fixed consecutive days? From: Bruno Luong Date: 14 Aug, 2012 06:55:05 Message: 7 of 7 "Karren" wrote in message ... > > What if I only need the first (and subsequent) output(s) starting from the 3rd consecutive number that exceed 130? For this case, the answer should be > > ans = 145 > ans = 155 and 130 Please replace the appropriate command with this: c=arrayfun(@(i1,i9) data(i1:i9), i1+2, i9, 'unif', 0); Bruno

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.