remove single outliers from vector
조회 수: 1 (최근 30일)
이전 댓글 표시
the device creates a vector for me where only double values are true, and all the rest I need to zero
close all
clear all
clc
x=[ 0 1 1 0 0 0 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 ];
y1need=[ 0 1 1 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 ];
%
y=find(x>0);
%
for i = 1:length(x)-1
if y(i)+1<y(i+1)
y1(i)=0
else
y1(i)=y(i)
end
end
% p.c. code works but gives error like this, how to fix it?
Index exceeds the number of array elements (13).
Error in Test (line 9)
if y(i)+1<y(i+1)
% p.c. 2 is there any special functions in matlab for this?
댓글 수: 0
채택된 답변
KSSV
2021년 4월 1일
x=[ 0 1 1 0 0 0 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 ];
y = [ 0 1 1 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 ];
ii = zeros(size(x));
jj = x > 0;
ii(strfind([0,jj(:)'],[0 1])) = 1;
idx = cumsum(ii).*jj;
iwant = x ;
for i = 1:length(unique(idx))
if length(idx(idx==i)) == 1
iwant(idx==i) = 0 ;
end
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!