"Alan Leung" <twaleung@engmail.uwaterloo.ca> wrote in message <gsin21$p26$1@fred.mathworks.com>...
> Hi,
>
> Matrix A is defined as:
>
> A = [5000;5000;6000;6000;6000;7000;7000;7000;7000;8000;8000;8000;8000;8000;];
>
> A represents samples that can be randomly chosen. It follows uniform distribution, i.e. the chance of getting A(1,1) is the same as A(3,1) or A(8,1).
>
> Now I create matrix B such that
>
> B = round(rand(10000,1)*size(A,1));
>
> Now I would like to convolve B into A (B as the index on A, A as the actual number) such that C can be something like:
>
> C = [8000;6000;5000;5000;....] (depends on the index defined in B)
>
> I am wondering how I can do that?
>
> Thanks,
>
> Alan
I believe you are misusing the term "convolve" here, Alan. If I understand you correctly, you simply want this:
C = A(B);
It is incorrect to use 'round' in the way you have it here. If size(A,1) = 14, there is a 1 in 28 chance that any given position in B will have the value 0 which is not a valid index. Also it is not uniformly distributed. There is only half the probability of a 14 index value as in the remaining indices. What you want is:
B = ceil(rand(10000,1)*size(A,1);
Roger Stafford
