Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: vectorize this
Replies: 4   Last Post: Mar 6, 2012 7:02 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Marios Karaoulis

Posts: 87
Registered: 5/10/10
vectorize this
Posted: Jan 31, 2012 2:57 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.