How to quickly find the indecies of elements in an array?

조회 수: 1 (최근 30일)
Benson Gou
Benson Gou 2021년 5월 23일
댓글: Torsten 2021년 5월 23일
Dear All,
I have an array A which contains integers. I have another array B. I want to find out the indecis of B in A.
For example, A = [1 9 2 8 3 7 4 6 5], B = [5 6 7]. The indecis of B in A is [9 8 6].
Thanks.
Benson

채택된 답변

per isakson
per isakson 2021년 5월 23일
편집: per isakson 2021년 5월 23일
A = [1 9 2 8 3 7 4 6 5];
B = [5 6 7];
[~,ix] = ismember( B, A )
ix = 1×3
9 8 6

추가 답변 (1개)

Torsten
Torsten 2021년 5월 23일
indices = find(A==B)
  댓글 수: 2
Benson Gou
Benson Gou 2021년 5월 23일
Hi, Torsten,
I got an error message: Matrix dimensions must agree.
Thanks.
Benson
Torsten
Torsten 2021년 5월 23일
Ok, seems a loop is required to find the indices for more than one element using the "find" command.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by