ho to get rid of repeated cells in cells arrays functions

Hello..
I have a cells array as follows:
contextt =
{24x1 cell} {25x1 cell} {26x1 cell}
I need to find the repeated cells in each column of the cells..
I used the following code , but doesn't help
[~,idx]=unique(cell2mat(contextt),'rows');
context_arr=contextt(idx,:)
with the following error:
Cannot support cell arrays containing cell arrays or objects
I changed the command 'rows' to 'columns' in the secod fucntion , but also doesn't work... also I want to results to be shown for the cells array contextt any advice Regards

 Accepted Answer

contextt={{1 2 3 4},{1 1 2 5},{2 2 2 6 7}}
out=cellfun(@(x) unique(cell2mat(x)),contextt,'un',0)

7 Comments

or
out=cellfun(@(x) num2cell(unique(cell2mat(x))),contextt,'un',0)
Hi Azzi.. it gives me error message:
Error using cell2mat (line 46)
All contents of the input cell array must be of the same data type.
Error in @(x)unique(cell2mat(x))
my data is in the type of characters (same like this: GO:0008150)
can you post a sample of your data?
try this
contextt={{'1' '20' '3'},{'1' '1' '2'},{'2' '2' '2'}}
out=cellfun(@(x) unique(x),contextt,'un',0)
@Azzi: Would this simpler version work also:
out=cellfun(@unique, contextt, 'un', 0)
? I cannot try it currently. Anonymous functions are slower than function handles in CELLFUN.
my data is same like this:
'a0' 'a0.b0' 'a0.b0.d6'
'a0' 'a0.d2' 'a0.d2.c2'
'a0' 'a0.d2' 'a0.d2.b1'
'a0' 'a0.e0' 'a0.e0.d8'
'a0' 'a0.c1' 'a0.c1.d9'
'a0' 'a0.c1' 'a0.c1.c3'
@Jwana: Accepting an answer means that it solves your problem. Is the problem solved already?

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!