I have a probability vector e.g., P = [0.1,0.2,0.3,0.4]. Then I use the command cumsum to create another vector Q = cumsum(P) = [0.1,0.3,0.6,1.0] I generate a Uniform [0,1] random vector,X = [0.11,0.72,0.32,0.94], and I want to know whether each entry of X is lying between [0,0.1] or [0.1,0.3] or [0.3,0.6], or [0.6,1.0] and I want to return a vector, which contains the index of the interval that each entry of X belongs to.
Is there a fast way of doing this, without writing a for loop?