Difference between MATLAB hough and my implementation I am trying to recreate MATLAB's hough function with mine. My code follows

function [H,T,R] = my_hough(x,dr,dtheta)
    rows = size(x,1);
    cols = size(x,2);
    D = sqrt((rows - 1)^2 + (cols - 1)^2);
    Nr = 2*(ceil(D/dr)) + 1;
    diagonal = dr*ceil(D/dr);
    R = -diagonal:dr:diagonal;
    T = -90:dtheta:90-dtheta;
    Ntheta = length(T);
    H = zeros(Nr,Ntheta);
    for i = 1:Ntheta
        for n1 = 1:rows
            for n2 = 1:cols
                if x(n1,n2)==1
                    r = n2*cos(T(i)*pi/180) + n1*sin(T(i)*pi/180);
                    [~,j] = min(abs(R-ones(1,Nr)*r));
                    H(j,i) = H(j,i) + 1;
                end
            end
        end    
    end
end


where dr and dtheta are distance and angle resolution. Printing the difference between my Hough table and MATLAB's there are many zeros, but there are also some non-zero elements. Any idea why this is happening?
I don't have the rep to comment on Dima's answer, but the code in the question does convert the $\theta$ to radians already.

This is my implementation of the routine for detecting lines:

[ theta,rho,height,width,Accumulator] = SHTanalyse( m,delta_theta,delta_rho )
%% Get dimensions of input image
[height, width] = size(m);

% Create array for theta 
theta = -90:delta_theta:90;
costheta = cosd(theta); % Create lookup tables to optimize computation of cos theta and sin theta
sintheta = sind(theta);

% Find bounds on rho
rhomax = round(sqrt(height^2 + width^2));

% Create array for rho
rho = -rhomax:delta_rho:rhomax;

% Get edgel coordinates
[yEdges,xEdges] =  find(m);

% Initialize the accumulator
Accumulator = zeros(numel(rho),numel(theta));

% Voting process
for k = 1:numel(yEdges) % Loop through edge pixels
    for t = 1:numel(theta)
        % Compute the corresponding rho
        rhvalue = round(xEdges(k).*costheta(t) + yEdges(k).*sintheta(t));
        % Increment accumulator
        Accumulator(rhvalue + round(0.5*numel(rho)) + 1,theta(t) + 90 + 1) = Accumulator(rhvalue + round(0.5*numel(rho)) + 1,theta(t) + 90 + 1) + 1;
    end
end    


You can compare its performance with the MATLAB's own Hough function to figure out the discrepancy.