Split large vector into smaller vectors based on upper and lower limits
Show older comments
Hi all, i'm relatively new to MATLAB and coding in general, so i would love some help for a problem which is as follows.
I have a vector containing 6million data points representing wind speeds ranging from 0 to above 30 m/s. There is also another vector with corresponding datetimes.
For a job, when the wind speed reaches 20 m/s, i need to find the time taken for the wind speed to reach 30 m/s. So i would like to split the large vector into separate vectors where the first value is 20 and the final value is 30. These occurances happpen several times throughout the data, so i want to create an individual vector each time the wind speed exceeds 20 and reaches 30.
As an additional condition, the wind speed data is very messy, and there are sometimes single outliers which may be above or below the thresholds given above. Therefore, i would like the code to create the first point when there are 2 consecutive points above 20 m/s, and create the final point when there are 2 consecutive points above 30 m/s.
Any help would be greatly appreciated, thanks !
5 Comments
Walter Roberson
on 12 Oct 2021
Once you have started a run of > 20, what should be considered to end the run?
18 25 25 25 19 19 25 30 30
if the answer is that two in a row below 20 ends the run, then the 30's would not be counted, as you defined a run as starting with at least two consecutive > 20 and if the 19 19 ends the previous run then the 25 after that would only be a single > 20 .
Joshua Pretorius
on 12 Oct 2021
Walter Roberson
on 12 Oct 2021
18 25 25 25 19 19 10 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 30 30
It seems clear to me that by the time of the 0's (at latest) the burst > 20 has ended, and that anything after that is a different stretch. If it ended with (say) 0 0 0 0 ... 0 24 26 30 30 then it would be obvious that the 24 26 would be the start of a run and the 30's should go with that 24 26, not all the way back to the original 25's.
So we need rules for when a run of > 20 is considered to end. You have already said there may be outliers and you implied single outliers are not considered to end the run... so should 2 values < 20 in a row be considered to end a run ?
Joshua Pretorius
on 12 Oct 2021
Mathieu NOE
on 12 Oct 2021
hello
my 2 cents suggestion
why not first smooth a bit your data (using smoothdata)
then loop through the data and serach for conditions :
1/ start point is when 2 consecutive samples are in the band 20 +/- 1 (I need a certain tolerance here)
2/ stop point is when 2 consecutive samples are in the band 30 +/- 1 (I need a certain tolerance here)
3/ this portion of data is valid if there is max 1 (or tbd qty) outliers. The reason of data smoothing was to get rid of the single outliers problem somehow.
if you could share a portion of data , I could try my logic
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!