How to delete repeated elements in column

I have 10x4 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

댓글 수: 2

Image Analyst
Image Analyst 2016년 3월 20일
Why? What's the use case for this request?
Pat
Pat 2016년 3월 20일
i want to remove consecutive duplicates for next stage of processing

댓글을 달려면 로그인하십시오.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 3월 20일

0 개 추천

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)

댓글 수: 1

Pat
Pat 2016년 3월 20일
Thanks Azzi,it helped me a lot.can u suggest a book for matlab programming

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Just for fun에 대해 자세히 알아보기

질문:

Pat
2016년 3월 20일

댓글:

Pat
2016년 3월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by