Building of height difference matrix