adding pairwise terms in matlab efficent