function [w1 w2] = rownorm2w(a,b)

% PURPOSE: row normalizes two spatial weight matrices across both 
%          matrices
% ------------------------------------------------------
% USAGE: [w1 w2] = rownorm2w(a,b)
% where:     a = first weight matrix 
%            b = second weight matrix
% ------------------------------------------------------
% RETURNS: w1 = first spatial weight matrix (row normalized across both)
%          w2 = second weight matrix (row normalized across both)
% ------------------------------------------------------
% References: Kelley Pace, Spatial Statistics Toolbox 2.0
%             Pace and LeSage, Introduction to Spatial Econmetrics
%             CRC Press, 2009
% ------------------------------------------------------
% 
% written by:
%
% Donald J. Lacombe
% Research Associate Professor
% Regional Research Institute
% 886 Chestnut Ridge Road
% PO Box 6825
% Morgantown, WV 26506-6825
% donald.lacombe@mail.wvu.edu
%
% For use with the spatial econometrics toolbox
% jlesage@spatial-econometrics.com

w = cat(2,a,b);
ind = (w~=0);
sind = sum(ind,2);
[r c] = size(w);
indsind = zeros(r,c);
for i = 1:r
    indsind(i,:) = ind(i,:)./sind(i);
end
w1 = indsind(1:r,1:r);
w2 = indsind(1:r,r+1:end);
