|
clear all
I=[1 1 1 1 1 0 1 1 1 0 1 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1];
T = 4;
Idiff = diff(I);
index1 = find(Idiff == 1);
index2 = find(Idiff == -1);
if length(index1) == 0 | length(index2) == 0,
%%%全1或者全0的情况,根据自己需要单独处理一下
coutinue;
else
if length(index1) == length(index2)+1,
tt = index2 - index1(1:end-1);
tt = [tt,length(I)-index1(end)];
index3 = find(tt <= T);
for ii = 1:length(index3);
I(index1(index3(ii))+1:index1(index3(ii))+tt(index3(ii))) = 0;
end
elseif length(index1) == length(index2)-1,
if index2(1) <= T;
I(1:index2(1)) = 0;
end
tt = [index2(2:end) - index1];
index3 = find(tt <= T);
for ii = 1:length(index3);
I(index1(index3(ii))+1:index1(index3(ii))+tt(index3(ii))) = 0;
end
elseif length(index1) == length(index2),
if index1(1)>index2(1),
if index2(1) <= T;
I(1:index2(1)) = 0;
end
tt = index2(2:end) - index1(1:end-1);
index3 = find(tt <= T);
for ii = 1:length(index3);
I(index1(index3(ii))+1:index1(index3(ii))+tt(index3(ii))) = 0;
end
if length(I)-index1(end) <=T,
I(index1(end):end) = 0;
end
elseif index1(1) < index2(1),
tt = index2 - index1;
index3 = find(tt <= T);
for ii = 1:length(index3);
I(index1(index3(ii))+1:index1(index3(ii))+tt(index3(ii))) = 0;
end
end
end
end
I |
|