I need help for Matlab vectorization of this code -


i new on matlab, don't know proper basics of vectorization.. trying vectorize function.

function  indc  =  patchsearch(x, row, col, off, nv, s, i)  [n m]   =   size(i); f2      =   size(x,2);  rmin    =   max( row-s, 1 ); rmax    =   min( row+s, n ); cmin    =   max( col-s, 1 ); cmax    =   min( col+s, m );  idx     =   i(rmin:rmax, cmin:cmax); idx     =   idx(:); b       =   x(idx, :);         v       =   x(off, :);   dis     =   (b(:,1) - v(1)).^2; k = 2:f2     dis   =  dis + (b(:,k) - v(k)).^2; end dis   =  dis./f2; [val,ind]   =  sort(dis);  indc        =  idx( ind(1:nv) ); %indc = idx(dis<250); 

i need experts vectorizating function thanks

you can replace following loopy portion of code -

dis     =   (b(:,1) - v(1)).^2; k = 2:f2     dis   =  dis + (b(:,k) - v(k)).^2; end 

with bsxfun implementation -

dis = sum(bsxfun(@minus,b,v).^2,2); 

the assumption here f2 number of columns in b, same number of elements in v , looking @ code way b , v initialized, seems quite right.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -