vectorise the for loop below to find the xor
Show older comments
Hi,
I have the following piece of code which due to the for loop takes very long to execute. As the number of loops increase it is quite critical for me that the code take as less time as possible for execution.
for i=1:10
source_data(i,:)=rand(1,20)<.8;
end
for i=1:15
G(:,i)=rand(10,1)<.9;
end
z=1;
while(i<=15)
for j=1:10
if(G(j,i)==1)
intersum(z+1,:)=xor(intersum(z,:), source_data(j,:));
z=z+1;
end
end
C(i,:)=intersum(z,:);
i=i+1;
end
Any suggestions is quite helpful. I am using an older version of Matlab 7.6
Thanks, Bhavya
Answers (1)
Sean de Wolski
on 2 Feb 2012
the first two for-loops can be easily vectorized with
source_data = rand(10,20)<0.8;
G = rand(10,15)<0.9;
I'm sure the last two can be vectorized as well but I don't have time to look at it right now.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!