How to remove similar element in cell?

Dear Sir,
Is that possible to remove the similar element in each cell based on previous cell. for example:
z={[],[],282,[195,249,282],[195,249,282],[195,249,282],[195,249,282],[103,195,249,282],[103,195,249,282] [104,1,50,103,195,249,282]}
My I get the expected results below:? results = {[], [], 282, [195,249], [195,249], [195,249], [195,249], [103],[], [104,1,50],}
Thanks in advance and sorry for bothering you.

2 Comments

Why there are four [195,249] in your expected result? Aren't you trying to remove all duplicate numbers?
Dear Albert, Yeah that true. I did mistake. therefore the expected results is : results = {[], [], 282, [195,249], [], [], [], [103],[], [104,1,50],}

Sign in to comment.

 Accepted Answer

setdiff(), going through a loop
results=z;
for k=2:length(z)
results{k}=setdiff(z{k},z{k-1});
end
celldisp(results);

3 Comments

Dear Fangjun, setdiff() does not work for cell.
thanks
See updates with the code.
Thanks Fangjun, that really amazing. it works

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!