【发布时间】:2011-07-14 23:40:49
【问题描述】:
我想对这两行代码进行矢量化处理。我最近才了解矢量化。我知道如何矢量化 sumsurface 线,但我不确定如何包含 if 语句,我真的很想矢量化整个 for 循环并摆脱它。我想矢量化以改善运行时我现在拥有的代码运行速度非常慢。我预先分配了有助于提高运行时间的数组。我以前忘记这样做了。如果我能得到任何帮助,将不胜感激。
pH = linspace(2,12, 6000);
for j = 1:300
nAsp = randi([10, 30],[1,1]);%865
nGlu = randi([12, 38],[1,1]);%1074
nLys = randi([11, 33],[1,1]);%930
nArg = randi([10, 30],[1,1]);%879
nCys = randi([2, 8],[1,1]); %214
nTyr = randi([5, 17],[1,1]); %462
nHis = randi([4, 12],[1,1]); %360
for i = 1: len;
sumsurface(i) = (nAsp).*(-(10.^((pH(i)-asp) )./(10.^((pH(i)-asp) )+1)) )+ (nGlu).*(-(10.^((pH(i)-glu) )./(10.^((pH(i)-glu) )+1)))+(nCys).*(-(10.^((pH(i)-cys) )./(10.^((pH(i)-cys) )+1)))+ (nTyr).* (-(10.^((pH(i)-tyr) )./(10.^((pH(i)-tyr) )+1)))+ (nHis).*(1./(10.^((pH(i)-his) )+1))+ (nLys).*(1./(10.^((pH(i)-lys) )+1))+ (nArg).*(1/(10.^((pH(i)-arg) )+1));
if sumsurface(i) < .01 && sumsurface(i) > -.01
%disp(sumsurface(i));
disp(pH(i));
x(1+end) = pH(i);
aspl(1+end) = nAsp;
glul(1+end) = nGlu;
cysl(1+end) = nCys;
tyrl(1+end) = nTyr;
hisl(1+end) = nHis;
lysl(1+end) = nLys;
argl(1+end) = nArg;
end
end
end
【问题讨论】:
标签: matlab vectorization