if statement between cells arrays

I need to compare between values in cells arrays such as I have :
p =
'GO:0008150'
'GO:0016740'
'GO:0016787'
'GO:0008150'
'GO:0016740'
'GO:0016740'
'GO:0016787'
'GO:0016787'
'GO:0016787'
'GO:0006810'
'GO:0006412'
'GO:0004672'
'GO:0008150'
'GO:0008150'
'GO:0006810'
'GO:0016192'
'GO:0006810'
'GO:0005215'
and c:
c =
'GO:0016740'
'GO:0016787'
'GO:0006810'
'GO:0006412'
'GO:0004672'
'GO:0016779'
'GO:0004386'
'GO:0003774'
'GO:0016298'
'GO:0016192'
'GO:0005215'
'GO:0030533'
'GO:0016787'
'GO:0006810'
'GO:0006412'
'GO:0003774'
'GO:0005215'
'GO:0030533'
so I want to make if statement that: I want elements from vector 'p' not occure in vector 'c' . the code I made is:
for i=1:length(p)
if p(i)~=c(:)
level1_root=p{i}
break
else
%disp('There is no root node in the system!!')
end
end
and the error message is: ??? Undefined function or method 'ne' for input arguments of type 'cell'
it is worked for normal vector , but not worked for cells array (my case)
advice please

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 25 Okt. 2012
Bearbeitet: Azzi Abdelmalek am 25 Okt. 2012

1 Stimme

out=unique(p(cellfun(@(x) ~ismember(x,c),p)))

2 Kommentare

Jwana
Jwana am 25 Okt. 2012
excellent!! but how can I get rid of repeated values
Azzi Abdelmalek
Azzi Abdelmalek am 25 Okt. 2012
add unique function

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Matt J
Matt J am 25 Okt. 2012

1 Stimme

setdiff(p,c)
Matt Fig
Matt Fig am 25 Okt. 2012
Bearbeitet: Matt Fig am 25 Okt. 2012

0 Stimmen

This will fix your code:
for i=1:length(p)
if p{i}~=c{i}
level1_root=p{i}
break
else
%disp('There is no root node in the system!!')
end
end
But I am confused. You say that you want to make sure that the values in p are not in c. Yet this code only checks that the values aren't in the same position, not that they don't exist at all. Have a look at:
ismember(p,c) % 1s show where an element of p is in c...
So which is it? Do you want to make sure that no element of p is in c (as you say), or that no element of p is in the same position as it is in c (what your code checks)?

4 Kommentare

Jwana
Jwana am 25 Okt. 2012
thank you for ur response.. I tried this code before and the following error message appears: ??? Error using ==> or Not enough input arguments.
I am using this code in bioinformatics.. and there is should be one root in p vector not occur in c vector ( only one value) ,so this code was working good but with normal values
Matt Fig
Matt Fig am 25 Okt. 2012
Bearbeitet: Matt Fig am 25 Okt. 2012
That is funny, I get no error when I run it with your p and c. I guess you are using a different p and c than you show....
p = {'GO:0008150'
'GO:0016740'
'GO:0016787'
'GO:0008150'
'GO:0016740'
'GO:0016740'
'GO:0016787'
'GO:0016787'
'GO:0016787'
'GO:0006810'
'GO:0006412'
'GO:0004672'
'GO:0008150'
'GO:0008150'
'GO:0006810'
'GO:0016192'
'GO:0006810'
'GO:0005215'};
c = {'GO:0016740'
'GO:0016787'
'GO:0006810'
'GO:0006412'
'GO:0004672'
'GO:0016779'
'GO:0004386'
'GO:0003774'
'GO:0016298'
'GO:0016192'
'GO:0005215'
'GO:0030533'
'GO:0016787'
'GO:0006810'
'GO:0006412'
'GO:0003774'
'GO:0005215'
'GO:0030533'};
for i=1:length(p)
if p{i}~=c{i}
level1_root=p{i}
break
else
%disp('No root node in the system!!')
end
end
No error in that at all. There also is no error here:
ismember(p,c)
But in any case, you got your answer.
Jwana
Jwana am 25 Okt. 2012
really strange!! when I copied your code it is worked !! maybe because these p and c cells vectors came from cells arrays processes?? in fact I need this method u mentioned because I have to make other process depends on it.
the code which I made to get 'p' and 'c' is the following:
Note: map is a cells arrays which has a long code it self I didn't mention here !!!
b={};
for i=1:length(map)
b=[b,map{i,1}];
end
b=b';
g={};
for i=1:length(map)
g=[g,map{i,2}];
end
g=g';
h={};
for i=1:size(map)
h=[h,map{i,3}];
end
h=h';
y=[g' h']';v=[b' b']';m=[y,v];
m(cellfun(@(x) ~x(1),m(:,1)),:) = [];

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Performance and Memory finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by