MATLAB Answers

## how to form a indexed matrix?

Asked by Shubham Mohan Tatpalliwar

### Shubham Mohan Tatpalliwar (view profile)

on 26 Nov 2018
Latest activity Commented on by Jan

### Jan (view profile)

on 26 Nov 2018
Accepted Answer by Jan

### Jan (view profile)

Row matrix
A=[0 2 3; 3 2 1; 2 3 1]
Column
B= 2
Index matrix
C=[10 20 50; 60 80 90 ; 20 60 40]
Result expected
i would first select colum As 2
And look for the values of C
Depending on row number from A
D=[0 80 60; 60 80 20; 80 60 20]

#### 0 Comments

Sign in to comment.

## 1 Answer

Answer by Jan

### Jan (view profile)

on 26 Nov 2018
Accepted Answer

The quetsion is not really clear. With some bold guessing:
A = [1 2 3; 3 2 1; 2 3 1];
B = 2;
C = [10 20 50; 60 80 90 ; 20 60 40];
CB = C(:, B);
D = CB(A)

#### 3 Comments

Shubham Mohan Tatpalliwar

### Shubham Mohan Tatpalliwar (view profile)

on 26 Nov 2018
i forget to put the zero terms
if A=0
then D=0
Shubham Mohan Tatpalliwar

### Shubham Mohan Tatpalliwar (view profile)

on 26 Nov 2018
Can u suggest me something for zero terms
Jan

### Jan (view profile)

on 26 Nov 2018
D = zeros(size(A));
m = (A ~= 0);
D(m) = CB(A(m));

Sign in to comment.