You can't write to a parallel-segmented matrix in the inner loop. Try this:
col = zeros(n,1);
d = P(i,:) + H(j,:);
col(j) = sum(d(:) ~= 0);
A(:,i) = col;
Not quite sure about the cell-array usage. If there's an issue there, it's likely to be because the cell-array has two rows instead of one. If you expect that call to find to only return 1 value, then state it explicitly: find(..., 1, 'first') and use a matrix for u2Had.