I would like to know how I can find out how long a certain event lasts.

4 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Jan
Jan el 15 de Mayo de 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)
iniTime = 2×1
0.0400 0.0920
finTime = data(fin, 1)
finTime = 2×1
0.0570 0.1420
spanTime = finTime - iniTime
spanTime = 2×1
0.0170 0.0500

Más respuestas (1)

Image Analyst
Image Analyst el 15 de Mayo de 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)
groups = 15×1
0 1 0 0 2 2 2 0 0 0
numRegions = 2
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
durations = 1×2
0 0.0310

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by