Detect monotonic decrease and record the corresponding rate

3 visualizaciones (últimos 30 días)
Joy
Joy el 26 de Mzo. de 2024
Editada: Joy el 27 de Mzo. de 2024
Assume I have the following data:
D1= {'3/25/2024 15:01:10' 15
'3/25/2024 15:01:26' 25
'3/25/2024 15:01:42' 25
'3/25/2024 15:01:58' 23
'3/25/2024 15:02:14' 22
'3/25/2024 15:02:30' 15
'3/25/2024 15:02:46' 25
'3/25/2024 15:02:50' 24
'3/25/2024 15:02:59' 23}
I'd like to find the rate the variable decreases from 25 to 15. For this dataset, once the value has reached 15, it will jump back up to 25, and I'd like to record the next decreasing rate (and repeat).
So for example, I would record 10/ ('3/25/2024 15:02:46' - '3/25/2024 15:02:30') or 10/(16 seconds)
The next rate would be 10 / ('3/25/2024 15:02:59' - '3/25/2024 15:02:50') or 10/(9 seconds).
I believe I need to use ischange to detect when the values jump back up to 25, and ignore noise. (Assuming that the decreasing rate is monotonic).
Thanks

Respuesta aceptada

Les Beckham
Les Beckham el 26 de Mzo. de 2024
Your "for example" text doesn't seem to match with finding how long it takes to decrease from 25 to 15.
So for example, I would record 10/ ('3/25/2024 15:02:46' - '3/25/2024 15:02:30') or 10/(16 seconds)
The next rate would be 10 / ('3/25/2024 15:02:59' - '3/25/2024 15:02:50') or 10/(9 seconds).
Your first example points are for an increase from 15 to 25 and your second example is for an decrease from 24 to 23.
If you really are wanting to find the average slopes of the decreases from 25 to 15. Try this approach (as a starting point at least). Note that I added an extra point to your data so there would be more than one decrease from 25 to 15.
D1= {'3/25/2024 15:01:10' 15
'3/25/2024 15:01:26' 25
'3/25/2024 15:01:42' 25
'3/25/2024 15:01:58' 23
'3/25/2024 15:02:14' 22
'3/25/2024 15:02:30' 15
'3/25/2024 15:02:46' 25
'3/25/2024 15:02:50' 24
'3/25/2024 15:02:59' 23
'3/25/2024 15:03:05' 15}; % << added a data point so there are two 25 to 15 transitions
T = cell2table(D1, 'VariableNames', {'timestamp', 'data'});
T.timestamp = datetime(T.timestamp(:))
T = 10x2 table
timestamp data ____________________ ____ 25-Mar-2024 15:01:10 15 25-Mar-2024 15:01:26 25 25-Mar-2024 15:01:42 25 25-Mar-2024 15:01:58 23 25-Mar-2024 15:02:14 22 25-Mar-2024 15:02:30 15 25-Mar-2024 15:02:46 25 25-Mar-2024 15:02:50 24 25-Mar-2024 15:02:59 23 25-Mar-2024 15:03:05 15
Since we only care about the cases where the data decreases from 25 to 15, eliminate any data that is not 25 or 15 and also eliminate any data before the first occurrence of 25.
idx = T.data == 25 | T.data == 15;
T = T(idx,:);
if T.data(1) ~= 25
T(1,:) = []
end
T = 5x2 table
timestamp data ____________________ ____ 25-Mar-2024 15:01:26 25 25-Mar-2024 15:01:42 25 25-Mar-2024 15:02:30 15 25-Mar-2024 15:02:46 25 25-Mar-2024 15:03:05 15
slope = diff(T.data) ./ seconds(diff(T.timestamp));
We only care about negative slopes so throw away any non-negative slopes.
slope = slope(slope < 0) % slopes in data units per second
slope = 2x1
-0.2083 -0.5263
  3 comentarios
Les Beckham
Les Beckham el 27 de Mzo. de 2024
You are quite welcome. If your problem is solved, please Accept the answer that best helped you solve it. If you have additional specific questions, please provide the details or additional data.
Joy
Joy el 27 de Mzo. de 2024
Editada: Joy el 27 de Mzo. de 2024
I'm concerned about the noise in my dataset. I'm trying to use ischange to detect when there are large changes. Now i'm trying to find each local maximum and the sequential minimum and taking the rate. Do you have any advice on this? Thanks

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 26 de Mzo. de 2024
Does this help?
D1= {'3/25/2024 15:01:10' 15
'3/25/2024 15:01:26' 25
'3/25/2024 15:01:42' 25
'3/25/2024 15:01:58' 23
'3/25/2024 15:02:14' 22
'3/25/2024 15:02:30' 15
'3/25/2024 15:02:46' 25
'3/25/2024 15:02:50' 24
'3/25/2024 15:02:59' 23};
t = cell2table(D1)
t = 9x2 table
D11 D12 ______________________ ___ {'3/25/2024 15:01:10'} 15 {'3/25/2024 15:01:26'} 25 {'3/25/2024 15:01:42'} 25 {'3/25/2024 15:01:58'} 23 {'3/25/2024 15:02:14'} 22 {'3/25/2024 15:02:30'} 15 {'3/25/2024 15:02:46'} 25 {'3/25/2024 15:02:50'} 24 {'3/25/2024 15:02:59'} 23
var = t{:, 2};
rows15 = find(var == 15)
rows15 = 2x1
1 6
dateTimes = D1(rows15, 1)
dateTimes = 2x1 cell array
{'3/25/2024 15:01:10'} {'3/25/2024 15:02:30'}

Categorías

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

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by