optimization - High time complexity reduction of the matlab code -
i trying run piece of code in matlab has high complexity despite matlab slow loops. please me optimize code below.
for k=1:th i=1:d-1 j=i+1:d if(dist(j,k)>dist(i,k)) t=classp1(k,i); classp1(k,i)=classp1(k,j); classp1(k,j)=t; end end end end where
size(classp1)=20x4276
size(dist)=4276x20
thank lot in advance
rinadi
you might able remove outer loop on k (untested since don't have data, might need tweaking):
for = 1:d-1 j = i+1:d iswap = find(dist(j, 1:th) > dist(i, 1:th)); classp1(iswap, [i, j]) = classp1(iswap, [j, i]) end end i not sure if saves lot in readability or in speed.
but goal? seems doing sorting matrix classp1 based on matrix dist (but not exactly). maybe there better solution using [~, idx] = sort(dist) , classp1(??, idx) = whatever.
Comments
Post a Comment