Azzera filtri
Azzera filtri

Separate and store values between peaks

2 visualizzazioni (ultimi 30 giorni)
CH
CH il 1 Ago 2021
Commentato: CH il 2 Ago 2021
Hello,
I have a device that records this value "counts". The motion is similar to sinusoidal signal in that it has peaks and troughs. The device starts at a zero position and records the count value and the corresponding time in ms every time a change is detected. I am interested in the data captured between the peaks (i.e. between 2110 and 2178 below) would like the store the data points (5 in the first case), both count and time values in one matrix and then the values between 2178 and 2175 in another and so on for the complete data set but I haven't been able to make much progress with it. Appreciate any help. Thanks.
Count Time
0 0
2110 204
8 127
24 11
25 6
24 4
1 160
2178 187
-9 117
0 17
-8 169
2175 152

Risposta accettata

Image Analyst
Image Analyst il 1 Ago 2021
Try this:
fileName = 'Count_Time Sample.xlsx'
data = readmatrix(fileName)
t = data(:, 2);
counts = data(:, 1);
plot(counts, 'b.-', 'MarkerSize', 20, 'LineWidth', 2);
hold on;
plot(t, 'r.-', 'MarkerSize', 20, 'LineWidth', 2);
grid on;
threshold = 1000;
peakIndexes = find(counts > threshold)
% Get data in between peaks
for k = 1 : length(peakIndexes) - 1
index1 = peakIndexes(k) + 1;
index2 = peakIndexes(k+1) - 1;
thisData = counts(index1 : index2)
end
You'll see
data =
0 0
2110 204
8 127
24 11
25 6
24 4
1 160
2178 187
-9 117
0 17
-8 169
2175 152
83 135
119 85
3 117
2032 143
17 363
2102 157
11 136
13 48
-10 203
2152 158
-8 404
2188 143
6 147
27 45
-8 180
2162 141
peakIndexes =
2
8
12
16
18
22
24
28
thisData =
8
24
25
24
1
thisData =
-9
0
-8
thisData =
83
119
3
thisData =
17
thisData =
11
13
-10
thisData =
-8
thisData =
6
27
-8
  5 Commenti
Image Analyst
Image Analyst il 1 Ago 2021
@CH, the first item on the FAQ is about cell arrays (and for good reason):
It will give you a good intuitive feel for when to use cell arrays and when you don't need to, and when to use braces, parentheses, or brackets. Admittedly, it can be very confusing but once you read the FAQ I think you'll understand much better what cell arrays are and how to use them.
CH
CH il 2 Ago 2021
Thanks. I'll have at read

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Object Properties in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by