I am sorry, I am not quite sure I understand- what exactly are youtrying to do?

Are we talking about P or p? What is P? MATLAB distinguishes between lower and upper case, ie. P is NOT the same thing as p. What has p to do with r? Are you trying to sum all the elements of the vector? Or count how many times a specific number occurs?