remove single outliers from vector

1 vue (au cours des 30 derniers jours)
Lev Mihailov
Lev Mihailov le 1 Avr 2021
Réponse apportée : KSSV le 1 Avr 2021
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?

Réponse acceptée

KSSV
KSSV le 1 Avr 2021
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

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by