I would like to know how I can find out how long a certain event lasts.
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Liz Román Aguayo
il 15 Mag 2022
Commentato: Liz Román Aguayo
il 15 Mag 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 Commenti
Risposta accettata
Jan
il 15 Mag 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
Più risposte (1)
Image Analyst
il 15 Mag 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 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!