



CORE_LEADINGEDGES Core computational routine for LEADINGEDGES.
Y = CORE_LEADINGEDGES(X) takes an M x N matrix X and returns a M x N
matrix Y, containing a logical 1 in each location Y(j,k) such that
X(j,k) AND ~X(j,k-1) for k>1 and X(j,k) for k==1.
The matrix Y is of type logical.
CONDITIONS
----------
X must be a matrix of type: DOUBLE, UINT8, LOGICAL.
X can not be sparse.
X should not contain NaN values; the results (i.e., whether NaN==0)
are compiler dependent.

0001 function Y = CORE_leadingedges(X) 0002 %CORE_LEADINGEDGES Core computational routine for LEADINGEDGES. 0003 % Y = CORE_LEADINGEDGES(X) takes an M x N matrix X and returns a M x N 0004 % matrix Y, containing a logical 1 in each location Y(j,k) such that 0005 % X(j,k) AND ~X(j,k-1) for k>1 and X(j,k) for k==1. 0006 % 0007 % The matrix Y is of type logical. 0008 % 0009 % CONDITIONS 0010 % ---------- 0011 % X must be a matrix of type: DOUBLE, UINT8, LOGICAL. 0012 % X can not be sparse. 0013 % X should not contain NaN values; the results (i.e., whether NaN==0) 0014 % are compiler dependent. 0015 % 0016 0017 Y = (X(1,:) ~= 0); 0018 Y = [Y; X(2:end,:) & ~X(1:end-1,:)]; 0019 0020 return; 0021 0022 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% TEST CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0025 % data = uint8((rand(1e6,3)*255) > 250); 0026 % tic; trig = CORE_leadingedges(data); t(1) = toc; 0027 % tic; trig2 = [(data(1,:)~=0) ; [(data(2:end,:)~=0) & (data(1:end-1,:)==0)]]; t(2) = toc; 0028 % printf('\nCORE_leadingedges took %5.3f sec and equivalent native code took %5.3f sec.', t(1), t(2)); 0029 % if (~isequal(trig,trig2)) 0030 % printf('The two calls did not produce the same results.'); 0031 % end