Obtain cell according to a corresponding value

1 次查看(过去 30 天)
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)

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2014-12-4
R=B(cell2mat(A(:,2)))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by