|
|
vectorize this
Posted:
Jan 31, 2012 2:57 PM
|
|
Hello all,
Could you help me vectorize the following code? Ideally, I need to remove the internal for loop.
num_mes=1890; num_param=225; Jx=rand(num_param,94221); Jy=rand(num_param,94221); Jz=rand(num_param,94221);
jac=zeros(num_mes,num_param); ind_data=randi(num_mes,num_mes,4);
jtmp=randi(94221,500,num_param);
for i=1:num_mes
A=ind_data(i,1); B=ind_data(i,2); M=ind_data(i,3); N=ind_data(i,4);
JA = [Jx(A,:) ;Jy(A,:); Jz(A,:)].'; JA = reshape(JA(mesh.T,:),[],4,3);
JM = [Jx(M,:); Jy(M,:) ;Jz(M,:)].'; JM = reshape(JM(mesh.T,:),[],4,3);
JN = [Jx(N,:) ;Jy(N,:) ;Jz(N,:)].'; JN = reshape(JN(mesh.T,:),[],4,3);
JB = [Jx(B,:) ;Jy(B,:); Jz(B,:)].'; JB = reshape(JB(mesh.T,:),[],4,3);
J_all=dot(JA-JB,JM-JN,3); tmp_jac=mean(J_all,2);
for k=1:num_param jtmp_this_iter =nonzeros( jtmp(:,k)); jac(i,k)=sum(tmp_jac(jtmp_this_iter)); end
end
|
|