You may want to seethe vectorization link here. I tried doing the vectorization for you, but just got confused in the loops. Since you understand your program better than I do, you might be able to find a way after reading the info in this link.
Allocate the 4th column of data in advance of the loops. Then, data has 3 (or 4) columns so what do you think you're getting for CR and P when you refer to data(i,1:2)? What's the third index? Why are you not specifying it?