Measuring distance between 2 "clumps" of data that meet certain conditions
2 次查看(过去 30 天)
显示 更早的评论
For a project, i have data in the form of wind speed (m/s) recorded with 1 minute intervals, starting from 2009 through to 2021. For the time of each recording I have created a datetime array in the form of yyyy:MM:dd_HH:mm:ss, and for the wind speed recorded at each minute i have created a double array.
The wind speed ranges from 0 through to 40+ m/s. For the project, the machnes can safely operate between wind speeds of 0-20 m/s. The machinery is damaged and can fall over when wind speeds reach 30m/s and above, Therefore, i need to measure the time taken for the wind speed to go from 20 to 30 m/s. The data is measured by 1 minute increments, from 2009 - 2020, so the data is quite messy when plotted. I have been given the following conditions that simplify measuring the time taken to go from 20 - 30 m/s.
- When speed exceeds 20 m/s, the first 2 consequtive points above the 20 m/s limit will be the 'initial point'.
- when speed exceeds 30 m/s, the first 2 consequtive points above the 30 m/s limit will be the 'final point'.
I need to record the time taken between the 'initial point' and the 'final point'. As there is a lot of data, the cases where wind speed goes from 20-30 occures several times, and ill need to record the corresponding time taken for each case.
Thanks very much :)
0 个评论
回答(1 个)
Yukthi S
2024-6-3
Hi Joshua,
To record the time intervals during which wind speeds escalate from 20 m/s to 30 m/s, we need a systematic approach to filter through the data, identify relevant 'initial' and 'final' points and then calculate the duration between these points.
Step-1: Initialize the arrays
%Let windSpeeds_arr be the data of speeds of wind and dateTime_arr is the datetime array.
%Let initial_ts and final_ts be the vectors which store the initial value timestamps and final value timestamps
%initializing initial_ts and final_ts
initial_ts= [];
final_ts= [];
Step-2: Identify ‘initial’ and ‘final’ points.
i=1
while i<=length(windSpeeds_arr)-1
%initial point condition according to question
if windSpeeds_arr(i)>20 && winSpeeds_arr(i+1) >20
%storing initial points timestamps in a column vector
initial_ts=[initial_ts;dateTime_arr(i)];
%searching for corresponding final point
%final point condition according to question
for j=(i+1): length(windSpeeds_arr)-1
if windSpeeds_arr(j)>30 && winSpeeds_arr(j+1)>30
%storing initial points timestamps in a column vector
final_ts=[final_ts;dateTime_arr(j)];
i=j+1;
break;
end
end
end
i=i+1;
end
Step-3: Calculate time intervals
%Calculate the time intervals between initial and final timestamps
timeIntervals= [];
for k=1: length(initial_ts)
time_duration=final_ts(k)-initial_ts(k);
timeIntervals= [ timeIntervals;minutes(time_duration)]; % Convert the duration to minutes and store
end
% Display the calculated time intervals
disp(timeIntervals);
The above code snippet will give you a basic idea of how to implement the logic to record time between ‘initial’ and ‘final’ points. You might want to adjust the logic depending on specific requirements.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 National Instruments Frame Grabbers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!