remove single outliers from vector

1 回表示 (過去 30 日間)
Lev Mihailov
Lev Mihailov 2021 年 4 月 1 日
回答済み: KSSV 2021 年 4 月 1 日
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?

採用された回答

KSSV
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 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by