Averaging of "similar data" in vector
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi. I have a vector x as below. There are clearly "groups" of data. I want to find the average of each group
This was my attempt, but I've come to a halt: Not sure what to do next.
D=unique(double(x))
F=diff(D)
F1=F;
F1(F1<20)=[]
idx=find(F1==F)
x =
72×1 uint16 column vector
13
13
13
13
14
14
14
14
14
58
58
58
59
59
59
59
59
60
103
103
104
104
104
104
104
104
104
193
193
194
194
194
194
194
195
195
238
238
238
239
239
239
239
239
239
283
283
284
284
284
284
284
284
284
328
329
329
329
329
329
329
329
330
373
374
374
374
374
374
375
375
375
0 Commenti
Risposta accettata
Jan
il 21 Feb 2017
Modificato: Jan
il 21 Feb 2017
If the blocks are identified by having a maximum distance thresh from the lowest to the highest element:
% UNTESTED
n = length(x);
thresh = 20
group = zeros(size(x));
lim = x(1) + thresh;
index = 1;
for k = 1:n
if x(k) > lim
index = index + 1;
lim = x(k) + thresh;
end
group(k) = index;
end
Y = splitapply(@mean, x, group); % Needs Matlab >= 2015b
0 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Matrix Indexing 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!