Got Questions? Get Answers.
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:
Take 2: Creating a matrix from information in two other matrixes

Subject: Take 2: Creating a matrix from information in two other matrixes

From: Ulrik Nash

Date: 10 Dec, 2010 18:07:05

Message: 1 of 2

Hi Everyone,

I know it is probably bad manners to start this post anew. But given that there was much confucion in the old thread, I hope it is okay just this once.

Suppose I have a matrix A

A = [2 3 1;1 5 0]

And another matrix B

B = [2 1 3;2 3 1]

Now I wish to create a matrix C, which looks like this

C = [3 2 1;0 1 5]

The procedure that creates C is in words as follows:
C(1,1):
"Look at B's row 1. Locate the number 1. Find the corresponding number i A. Answer=3"
C(1,2):
"Look at B's row 1. Locate the number 2. Find the corresponding number i A. Answer=2"
C(1,3):
"Look at B's row 1. Locate the number 3. Find the corresponding number i A. Answer=1"
C(2,1):
"Look at B's row 2. Locate the number 1. Find the corresponding number i A. Answer=0"
C(2,2):
"Look at B's row 2. Locate the number 2. Find the corresponding number i A. Answer=1"
C(2,3):
"Look at B's row 2. Locate the number 3. Find the corresponding number i A. Answer=5"

What code will generate C in general. In other words, the example shows rows of 2 and columns of 3. But what is there are r rows and c columns (in both A and B)?

Kind regards,

Ulrik.
 

Subject: Take 2: Creating a matrix from information in two other matrixes

From: Sean de

Date: 10 Dec, 2010 18:23:05

Message: 2 of 2

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <idtq89$62p$1@fred.mathworks.com>...
> Hi Everyone,
>
> I know it is probably bad manners to start this post anew. But given that there was much confucion in the old thread, I hope it is okay just this once.
>
> Suppose I have a matrix A
>
> A = [2 3 1;1 5 0]
>
> And another matrix B
>
> B = [2 1 3;2 3 1]
>
> Now I wish to create a matrix C, which looks like this
>
> C = [3 2 1;0 1 5]
>
> The procedure that creates C is in words as follows:
> C(1,1):
> "Look at B's row 1. Locate the number 1. Find the corresponding number i A. Answer=3"
> C(1,2):
> "Look at B's row 1. Locate the number 2. Find the corresponding number i A. Answer=2"
> C(1,3):
> "Look at B's row 1. Locate the number 3. Find the corresponding number i A. Answer=1"
> C(2,1):
> "Look at B's row 2. Locate the number 1. Find the corresponding number i A. Answer=0"
> C(2,2):
> "Look at B's row 2. Locate the number 2. Find the corresponding number i A. Answer=1"
> C(2,3):
> "Look at B's row 2. Locate the number 3. Find the corresponding number i A. Answer=5"
>
> What code will generate C in general. In other words, the example shows rows of 2 and columns of 3. But what is there are r rows and c columns (in both A and B)?
>
> Kind regards,
>
> Ulrik.
>

See the solutions in your other thread. Also, your example is wrong - as I explained in the other thread!

Tags for 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