performance - How to remove the for loop in the following MATLAB code? -
performance - How to remove the for loop in the following MATLAB code? -
i need perform next computation in image processing project. logarthmic of addition of h3. i've written next code loop has high computation time. there way eliminate loop?
k=1:i l=1:j ha(i,j)=ha(i,j)+log2((h3(k,l)/proba).^q); end; end;
thanks in advance!
edit:
for i=1:256 j=1:240 proba = 0; probc = 0; subproba = h3(1:i,1:j); proba = sum(subproba(:)); probc = 1-proba; k=1:i l=1:j ha(i,j)=ha(i,j)+log2((h3(k,l)/proba).^q); end; end; ha(i,j)=ha(i,j)/(1-q); k=i+1:256 l=j+1:240 hc(i,j)=hc(i,j)+log2((h3(k,l)/probc).^q); end; end; hc(i,j)=hc(i,j)/(1-q); e1(i,j) = ha(i,j) + hc(i,j); if e1(i) >= emax emax = e1(i); tt1 = i-1; end; end; end;
assuming 2 loops nested within other outer loops iterated i
, j
(though using i
, j
iterators not best practices) , assuming proba
, q
scalars, seek -
ha(i,j) = sum(sum(log2((h3(1:i,1:j)./proba).^q)))
using above code snippet, yon can replace actual code posted in edit section -
for i=1:256 j=1:240 subproba = h3(1:i,1:j); proba = sum(subproba(:)); probc = 1-proba; ha(i,j) = sum(sum(log2((subproba./proba).^q)))./(1-q); hc(i,j) = sum(sum(log2((subproba./probc).^q)))./(1-q); e1(i,j) = ha(i,j) + hc(i,j); if e1(i) >= emax emax = e1(i); tt1 = i-1; end end end
note in code, proba = 0;
, probc = 0;
removed over-written anyway later in original code.
performance matlab image-processing for-loop time
Comments
Post a Comment