This can be done by simply using the bins centres from one call to hist as the bins for the another
for example
[aCounts,aBins] = hist(a,nBins);
[bCounts,bBins] = hist(b,aBins);
note that all(aBins==bBins)
= 1
This method however will loose information when the min and max values of the two data sets are not similar*, one simple solution is to create bins based on the combined data
[~ , bins] = hist( [a(:),b(:)] ,nBins);
aCounts = hist( a , bins );
bCounts = hist( b , bins );
*if the ranges are vastly different it may be better to create the vector of bin centres manually
(after re-reading the question) If the bin widths are what you want to control not using the same bins creating the bin centers manually is probably best...
to do this create a vector of bin centres to pass to hist,
for example - note the number of bins is only enforced for one set of data here
aBins = linspace( min(a(:)) ,max(a(:) , nBins);
binWidth = aBins(2)-aBins(1);
bBins = min(a):binWidth:max(b)+binWidth/2
and then use
aCounts = hist( a , aBins );
bCounts = hist( b , bBins );