Search code examples
matlabrandompoisson

Please help me with line 8 of the code below?


Some one gave me this code to implement but I am not able to understand what Line 8 does in the code below. What does this mean y(y

clear;
lambda=0.1;
T=100;
M=50;
for i=1:M
 x=exprnd(1/lambda,1,2*lambda*T);
 y=cumsum(x);
pp{i}=y(y<T);
end

Solution

  • If line 8 is pp{i} = y(y < T), then it's creating a "cell array" (so now you can google it) with the {} syntax and setting element i to all the values in y that are less than T (i.e. 100)`. That is:

    y<T
    

    is an array the size of y with 1 in the places where the corresponding element of y is less than T.

    y(y<T)
    

    is then selecting only those elements. So it is probably smaller than y, and all the entries are less than T.

    And then:

    pp{i} = y(y<T)
    

    is assigning that array to element i of a "cell array". Cell arrays are like normal arrays except that each element can be a different type or a different size.