我有一个调用函数的代码,它给出了系统中每个基因的类型。我可以通过比较每个基因与其子代和父代的顺序来找到它。该代码在少量单元阵列上运行良好,但是当我将数量增加到数千时,它需要几个小时。代码是:
Types=[];
type1=level1_root; % it is fixed value (GO:0008150)
% sample values for p1 and c1 are given below
for k=1:100
type{k}=type_fc(p1,c1,type1); % a function call - see function below
type1=type{k}'; %'
temp1=num2cell(repmat(k+1,length(type1),1));
type1=[type1 temp1];
Types=[Types; type1];
end
% display the output:
Types
子功能:
function type=type_fc(p1,c1,type1)
type=[];
for j=1:length(type1)
for i=1:length(p1)
a=[p1(i),c1(i)];
if isequal(a(1), type1(j))
type=[type a(2)];
end
end
end
对于 13 个基因,我有这些样本输入:
p1'= %refer to parent genes
'GO:0008150'
'GO:0016740'
'GO:0016787'
'GO:0008150'
'GO:0016740'
'GO:0016740'
'GO:0016787'
'GO:0016787'
'GO:0016787'
'GO:0006810'
'GO:0006412'
'GO:0004672'
c1'= % refer to children genes
'GO:0016740'
'GO:0016787'
'GO:0006810'
'GO:0006412'
'GO:0004672'
'GO:0016779'
'GO:0004386'
'GO:0003774'
'GO:0016298'
'GO:0016192'
'GO:0005215'
'GO:0030533'
结果将是:Types =
'GO:0016740' [2]
'GO:0006412' [2]
'GO:0016787' [3]
'GO:0004672' [3]
'GO:0016779' [3]
'GO:0005215' [3]
'GO:0006810' [4]
'GO:0004386' [4]
'GO:0003774' [4]
'GO:0016298' [4]
'GO:0030533' [4]
'GO:0016192' [5]
你知道如何提高这段代码的速度吗?