The issue is with the line:
You want to take the index P(i) and grab the next 10 elements after that point, then put them into a row in M. This works fine for the first several iterations where P is picking out relatively small indices. However, some of the elements of P are picking out array elements near the end of noise, so there aren't 10 elements after those points to grab.
To put it more concretely, here is what P contains when I ran the code:
2 12 14 20 27 30 32 40 55 65 70 75 78 80 88
So, when you get to the last element of P, 88, you will want to grab elements 88-98 from noise and put them into M. However, noise only has 91 elements:
So to fix this error you need to replace the +10 with something else. You can use min(diff(P)) to see the minimum distance between consecutive indices in P, or min(abs(P-length(noise))) to see how close the last element in P is to the end of noise, or maybe you could just loop to length(P)-1 or length(P)-2, avoiding the last few large indices in P.