Averaging of "similar data" in vector
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Jan
2017년 2월 21일
편집: Jan
2017년 2월 21일
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
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!