필터 지우기
필터 지우기

Average of specific values based on condition

조회 수: 1 (최근 30일)
Filip Konecny
Filip Konecny 2017년 10월 18일
답변: KSSV 2017년 10월 18일
Hello, is it somehow to solve efficiently the following problem? I need to average only elements which are "together". See attached picture.

답변 (1개)

KSSV
KSSV 2017년 10월 18일
data = [1 2 3 4 5 6 6.5 10 12 12.5 15 16 17 ;20 20 20 20 20 20 20 13 13 13 20 20 20]';
idx = find(diff(data(:,2))~=0) ;
pos = [[1 ;idx+1] [idx ; length(data)]] ;
iwant = zeros(size(pos,1),1) ;
for i = 1:size(pos,1)
iwant(i) = mean(data(pos(i,1):pos(i,2),1)) ;
end
There would be more elegant procedures.

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by