Detect monotonic decrease and record the corresponding rate
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Les Beckham
il 26 Mar 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(:))
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
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
3 Commenti
Les Beckham
il 27 Mar 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.
Più risposte (1)
Image Analyst
il 26 Mar 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)
var = t{:, 2};
rows15 = find(var == 15)
dateTimes = D1(rows15, 1)
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!