MATLAB: How to delete repeated elements in column

consecutive elementsdeleton

I have 10×4 array with strings say
D={'Run' '' 'play' '';
'' 'go' '' 'sit' ;
'Run' '' 'play' '';
'' 'go' '' 'sit';
'' 'down' '' 'play';
'' 'go' '' 'sit'}
I want to remove consecutive elements in each column such that i get result as
res={'Run' '' 'play' '';
'' 'go' '' 'sit' ;
'' '' '' '';
'' '' '' '';
'' 'down' '' 'play';
'' 'go' '' 'sit'}
I tried using for loop and deleting ,the thing is that all elements with same names get deleted.
Kindly help

Best Answer

D={'Run' '' 'play' '';
'' 'go' '' 'sit' ;
'Run' '' 'play' '';
'' 'go' '' 'sit';
'' 'down' '' 'play';
'' 'go' '' 'sit'}
ii=unique(D);
v=0:numel(ii);
b=cellfun(@(x) v(ismember(ii,x)),D);
[n,m]=size(D);
c=b;
for l=1:m
for k=2:n
q=b(1:k-1,l);
idx=find(q,1,'last');
if b(k,l)==q(idx) ;
c(k,l)=0;
end
end
end
out=ii(c+1)