Hi everyone,
Suppose I have a matrix a:
a = [2 2;1 1;4 1;3 1;4 2];
and matrix b:
b = [3;5;1;5;2;4;2;3;5;1];
Then I want matrix c to be:
c = [4 1;4 2;2 2;4 2;1 1;3 1;1 1;4 1;4 2;2 2]
b is included row number of matrix a and matrix c has replaced each row number in matrix b with value number from matrix a.
Can anyone please help me?

 Akzeptierte Antwort

Jie Yang
Jie Yang am 6 Mai 2014
Bearbeitet: Jie Yang am 6 Mai 2014

0 Stimmen

for i=1:length(b)
c(i,:)=a(b(i),:);
end

Weitere Antworten (1)

Cedric
Cedric am 6 Mai 2014

2 Stimmen

A simple way is:
c = a(b,:) ;

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Gefragt:

Moe
am 6 Mai 2014

Kommentiert:

Moe
am 6 Mai 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by