How to reduce the time complexity?
Show older comments
The following code is taking much time to execute. What I wanted to do is.. Dividing the matrix of size 90x90 into 9x9 grids and calculating the angle counts in each range. Its taking a lot of time for computation. But I need to reduce this at any cost. Could not find the solution.
fsrc = sprintf('FeatureVector%d',ii);
%FeatureVector=zeros([100,8]);
cnt1=0; cnt2=0; cnt3=0; cnt4=0; cnt5=0; cnt6=0; cnt7=0; cnt8=0;
p = 1;
row = 1;
rlength = size(Gdir,1);
clength = size(Gdir,2);
while p<(rlength)
q = 1;
while q<(clength)
for i=p:p+8
for j=q:q+8
if Gdir(i,j)>=-180 && Gdir(i,j)<=-134
cnt1 = cnt1+1;
elseif Gdir(i,j)>=-135 && Gdir(i,j)<=-89
cnt2 = cnt2 + 1;
elseif Gdir(i,j)>=-90 && Gdir(i,j)<=-44
cnt3 = cnt3 + 1;
elseif Gdir(i,j)>=-45 && Gdir(i,j)<=-1
cnt4 = cnt4 + 1;
elseif Gdir(i,j)>=0 && Gdir(i,j)<=45
cnt5 = cnt5 + 1;
elseif Gdir(i,j)>=46 && Gdir(i,j)<=90
cnt6 = cnt6 + 1;
elseif Gdir(i,j)>=91 && Gdir(i,j)<=135
cnt7 = cnt7 + 1;
else
cnt8 = cnt8 + 1;
end
eval([fsrc '(row,1) = cnt1;']);
eval([fsrc '(row,2) = cnt2;']);
eval([fsrc '(row,3) = cnt3;']);
eval([fsrc '(row,4) = cnt4;']);
eval([fsrc '(row,5) = cnt5;']);
eval([fsrc '(row,6) = cnt6;']);
eval([fsrc '(row,7) = cnt7;']);
eval([fsrc '(row,8) = cnt8;']);
end
end
q = q + 9; row = row+1;
cnt1=0; cnt2=0; cnt3=0; cnt4=0; cnt5=0; cnt6=0; cnt7=0; cnt8=0;
end
p = p + 9;
end
dst = sprintf('FV%d.mat',ii);
s = ['save ./FeatureVectors/' dst ' ' fsrc ';'];
eval(s);
Accepted Answer
More Answers (0)
Categories
Find more on Linear Algebra 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!