필터 지우기
필터 지우기

get elements at x from array A without loop

조회 수: 1 (최근 30일)
Daniel Neubauer
Daniel Neubauer 2022년 10월 11일
댓글: Daniel Neubauer 2022년 10월 11일
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!

채택된 답변

Fangjun Jiang
Fangjun Jiang 2022년 10월 11일
A=10:10:90;
B=[1,1,3,6,7,5,4];
C=A(B)
C = 1×7
10 10 30 60 70 50 40

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by