One obvious problem with this code is where you try to access pairs(pr,2) but pairs is a one dimensional (4x1) vector. Perhaps you need to revise the definition of pairs?
pairs = nchoosek(1:4,1)
Maybe you meant this?
pairs = nchoosek(1:4,2)
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!