I would like to know how I can find out how long a certain event lasts.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Liz Román Aguayo
am 15 Mai 2022
Kommentiert: Liz Román Aguayo
am 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 Kommentare
Akzeptierte Antwort
Jan
am 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
Weitere Antworten (1)
Image Analyst
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!