func to assemble mat for local p averages