Find function in arrays

조회 수: 16 (최근 30일)
Metehan Geçer
Metehan Geçer 2022년 5월 14일
댓글: Voss 2022년 5월 14일
I am having two matrix. Selected elements in one matrix is present as elements in another matrix. Now i need to find the position of selected elements in the original matrix.
for example
yenidendonguyegirecekler =
-1321.6
-2119.8
-2825.5
-2937.5
-3205.4
-3340.9
-3895.0
-4080.2
-4320.9
fitnesshafiza =
-4080.2
-2937.5
-2825.5
-5749.6
-3205.4
-2119.8
-3340.9
-4320.9
-3895.0
-1321.6

채택된 답변

Voss
Voss 2022년 5월 14일
yenidendonguyegirecekler = [
-1321.6
-2119.8
-2825.5
-2937.5
-3205.4
-3340.9
-3895.0
-4080.2
-4320.9];
fitnesshafiza = [
-4080.2
-2937.5
-2825.5
-5749.6
-3205.4
-2119.8
-3340.9
-4320.9
-3895.0
-1321.6];
To find where the elements of yenidendonguyegirecekler are located in fitnesshafiza:
[~,idx] = ismember(yenidendonguyegirecekler,fitnesshafiza)
idx = 9×1
10 6 3 2 5 7 9 1 8
  댓글 수: 2
Metehan Geçer
Metehan Geçer 2022년 5월 14일
thx a lot <3
Voss
Voss 2022년 5월 14일
You're welcome!

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

추가 답변 (1개)

the cyclist
the cyclist 2022년 5월 14일
You can use the ismember function to find out whether each element of one vector is present in the other, and also the location.
  댓글 수: 1
Metehan Geçer
Metehan Geçer 2022년 5월 14일
for example ismember(A,B) ?

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by