remove single outliers from vector

1 visualización (últimos 30 días)
Lev Mihailov
Lev Mihailov el 1 de Abr. de 2021
Respondida: KSSV el 1 de Abr. de 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?

Respuesta aceptada

KSSV
KSSV el 1 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by