Obtain cell according to a corresponding value

1 Ansicht (letzte 30 Tage)
Dimitris Kokkinos
Dimitris Kokkinos am 4 Dez. 2014
Bearbeitet: Azzi Abdelmalek am 4 Dez. 2014
Hello everyone!I have 2 cell arrays. The first one is 5x2:
A={[1;2;3;4;5] 3;[12;13;14] 2;[1;2;3;4;8;9;10;22;23;24] 6;[4;5;6;8;9] 4;[5;6;7] 6};
The second one is 6x1
B={[32;21;13];[1;2;35];[5;6;7;8;9;0;2;3];[2];[1;3;5;7;9];[5;6;7]}
What I need is to create another cell array which will contain cells from array B selected and sorted according to A(:,2). The extracted result should be:
R={[5;6;7;8;9;0;2;3];[1;2;35];[5;6;7];[2];[5;6;7]}
R(1)=B(3)
R(2)=B(2)
R(3)=B(6)
R(4)=B(4)
R(5)=B(6)

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 4 Dez. 2014
R=B(cell2mat(A(:,2)))

Weitere Antworten (0)

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by