I would like to know how I can find out how long a certain event lasts.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Liz Román Aguayo
le 15 Mai 2022
Commenté : Liz Román Aguayo
le 15 Mai 2022
Hi!
I would like to know how I can find out how long a certain event lasts.
I have this data, where the first column is the time in seconds and the second column is acceleration data.
data =
0.019 0
0.04 0.45371
0.057 0
0.076 0.15127
0.092 0.22037
0.107 0.2317
0.123 0.22781
0.142 0.15654
0.156 0.08676
0.173 0.14319
0.19 0
0.206 0.19837
0.223 0.1897
0.239 0.13603
0.259 0.17579
I would like to know how long the acceleration stayed above a certain threshold (for example: 0.20) and save that value in a new vector each time it exceeds the threshold.
I'm new to using matlab and I'm a bit confused.
thank you very much
0 commentaires
Réponse acceptée
Jan
le 15 Mai 2022
data = [ ...
0.019 0
0.04 0.45371
0.057 0
0.076 0.15127
0.092 0.22037
0.107 0.2317
0.123 0.22781
0.142 0.15654
0.156 0.08676
0.173 0.14319
0.19 0
0.206 0.19837
0.223 0.1897
0.239 0.13603
0.259 0.17579];
m = [false, (data(:, 2) > 0.20).', false];
ini = strfind(m, [false, true]);
fin = strfind(m, [true, false]); % Or maybe: strfind(m, [true, false]) - 1
iniTime = data(ini, 1)
finTime = data(fin, 1)
spanTime = finTime - iniTime
Plus de réponses (1)
Image Analyst
le 15 Mai 2022
Do you mean like this:
data = [...
0.019 0
0.04 0.45371
0.057 0
0.076 0.15127
0.092 0.22037
0.107 0.2317
0.123 0.22781
0.142 0.15654
0.156 0.08676
0.173 0.14319
0.19 0
0.206 0.19837
0.223 0.1897
0.239 0.13603
0.259 0.17579];
times = data(:, 1);
values = data(:, 2);
threshold = 0.2;
mask = values > threshold;
% Find distinct regions
[groups, numRegions] = bwlabel(mask)
for k = 1 : numRegions
thisRegion = groups == k;
index1 = find(thisRegion, 1, 'first');
index2 = find(thisRegion, 1, 'last');
durations(k) = times(index2) - times(index1);
end
durations
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!