简体   繁体   中英

Vector of indexes to create matrix by accessing elements of another matrix

Consider an n-by-k matrix M and an p-by-1 vector of indexes V ranging from 1 to n. How can I create the p-by-k matrix C where each row corresponds to the entry of M referred to by the value in each row of V .

Example

M = 1 1
    1 2
    1 3
    1 4

and

V = 2
    1
    3

What I require is the matrix

C = 1 2
    1 1
    1 3

要将矩阵M的行V分配给矩阵C ,应编写:

C = M(V,:);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM