get elements at x from array A without loop

so, i have an array A=(1,2,3,4,5,6,7,8,9) and another array containing indexes B=(1,1,3,6,7,5,4). How to get a third one based on B such that C=[A(1),A(1),A(3),A(6),A(7),A(5),A(4)]?
I know how to do this by looping through b with i=1:length(B) and taking C(i)=A(B(i)) but would prefer to do this without any loop due to my real data being considerably larger than this example.
I'm new to matlab, any help is highly appreciated. thanks!

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

产品

版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by