#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# how to replace too many if statements

Posts: 2Member
Hi all,

Iam building a code in bioinformatics field.. I have 2 matrix comeing from a certain code as follows:

[code]
m1 =
'GO:0008150' 'GO:0016740'
'GO:0016740' 'GO:0016787'
'GO:0016787' 'GO:0006810'
'GO:0008150' 'GO:0006412'
'GO:0016740' 'GO:0004672'
'GO:0016740' 'GO:0016779'
'GO:0016787' 'GO:0004386'
'GO:0016787' 'GO:0003774'
'GO:0016787' 'GO:0016298'
'GO:0006810' 'GO:0016192'

m2 =
'GO:0008150' 'GO:0016787'
'GO:0008150' 'GO:0006810'
'GO:0006810' 'GO:0006412'
'GO:0016192' 'GO:0003774'
'GO:0006810' 'GO:0005215'
'GO:0005215' 'GO:0030533'[/code]

in each matrix, the first column is the parent of the second one... I need from the code to find the part of graph which can determine all relations between these cells... I have to find cell from column 1 that occurance in column 2, then take the cell from column 1 but from the same row of column 2 and find the similarity between it and onother cell in column 2 .. and so.. it is something like depth first search in graph theory

In general, How can I make a dynamic code (recursive) that can replace the following if statements:
[code]
for k=1:length(m1)
for ii=1:length(m1)
for j=1:length(m1)
for i=1:length(m2)
for e=1:length(m1)
if isequal(m2{i,1},m1{j,2})
x1=[m1(j,1) m2(i,2)];
x11=[x1;x11];
if isequal(m1{j,1},m1{k,2})
x2=[m1(k,1),m2(i,2)];
x22=[x2;x22];
if isequal(m1{k,1},m1{ii,2})
x3=[m1(ii,1),m2(i,2)];
x33=[x3;x33];
if isequal(m1{ii,1},m1{e,2})
x4=[m1(e,1),m2(i,2)];
x44=[x4;x44];
.
.
and so..x_total=[x11;x22;x33;x44...]
end
end
end
end
end
end
end[/code]

Note that the if statemtnes are not determined( it depends on m1 & m2 which are also not always constants)

· ·