Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Convolve two matrices into one matrix

Subject: Convolve two matrices into one matrix

From: Alan Leung

Date: 20 Apr, 2009 20:48:01

Message: 1 of 3

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

Subject: Convolve two matrices into one matrix

From: Roger Stafford

Date: 20 Apr, 2009 21:05:04

Message: 2 of 3

"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

Subject: Convolve two matrices into one matrix

From: Bruno Luong

Date: 20 Apr, 2009 21:06:02

Message: 3 of 3

"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));

Don't do ROUND, but CEIL for two reasons:
- ROUND can give 0, which is not good for indexing in A!
- P(B==0) = P(B==size(A)) = 1/2 * P(B = someothernumber) which is no longer a uniform distribution.



>
> 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)
>

Simply:
C = A(B) ;

So here is summarize the code put together

A = [5000;5000;6000;6000;6000;7000;7000;7000;7000;8000;8000;8000;8000;8000];
B = ceil(rand(10000,1)*size(A,1));
C=A(B)

% Bruno

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us