我有一個調用函數的代碼,它給出了系統中每個基因的類型。我可以通過比較每個基因與其孩子和父母的順序來找到它。代碼工作正常,只有一小部分單元陣列,但是當我將數量增加到數千時,需要花費數小時。的代碼是:在Matlab中增加函數調用的速度
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]
你有沒有任何想法如何提高這段代碼的速度?
如果你有類似的問題,你可以試試[codereview](http://codereview.stackexchange.com) –