Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 1494
Number of posts: 2174

This Forum Only

how to replace too many if statements Posted by Gloria99 on 13 Nov 2012 at 1:04 AM
Hi all,

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

```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'```

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:
```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```

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

Thread Tree
Gloria99 how to replace too many if statements on 13 Nov 2012 at 1:04 AM

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.