필터 지우기
필터 지우기

Split large vector into smaller vectors based on upper and lower limits

조회 수: 8 (최근 30일)
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
Joshua Pretorius
Joshua Pretorius 2021년 10월 12일
Hi Walter,
i've atatched a quick sketch which aims to show the rules for the start and end of each run. I hope this helps explain what i am aiming for,
Thanks!
Mathieu NOE
Mathieu NOE 2021년 10월 12일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2021년 10월 12일
편집: Matt J 2021년 10월 12일
Using this File Exchange submission,
vector = [8,29,18,21,23, 18,19,25,32,31 10,10, 21,26, 33,33];
D=discretize(vector,[-inf,20,30,inf],'IncludedEdge','right');
D=medfilt1(D,3); %outlier removal
x=(D<2);
D(x)=interp1(find(~x),D(~x),find(x),'previous');
Vectors=groupFcn(@(x) {x}, vector,groupTrue(D==2));
Vectors{:}
ans = 1×5
21 23 18 24 25
ans = 1×2
21 26
  댓글 수: 6
Matt J
Matt J 2021년 11월 7일
Then my example should be what you need.
Joshua Pretorius
Joshua Pretorius 2021년 11월 9일
Thanks Matt, works perfectly ! Very much appreciated !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by