Find position of numbers in array

조회 수: 1 (최근 30일)
saphir alexandre
saphir alexandre 2022년 2월 7일
댓글: DGM 2022년 2월 7일
Hi,
so i have an array W = [11, 56, 22, 45, 29]
then i use Z = mink(W,2) to find the 2 lowest numbers in W
how do i output the position of the numbers found in Z from the array W?
I tried find(Z) but i got the positions of the numbers in array Z, not their position in array W
For this exemple i used small numbers but the actual W has more then 200 numbers so typing a code for each would take forever

답변 (1개)

DGM
DGM 2022년 2월 7일
편집: DGM 2022년 2월 7일
You can specify a second output argument to get the linear index of the elements represented by Z:
W = [11, 56, 22, 45, 29]
W = 1×5
11 56 22 45 29
[Z idx] = mink(W,2)
Z = 1×2
11 22
idx = 1×2
1 3
  댓글 수: 2
saphir alexandre
saphir alexandre 2022년 2월 7일
thank you so much!
DGM
DGM 2022년 2월 7일
If you find that the answer has sufficiently satisfied the question, you can accept the answer. This moves it to the 'accepted' queue, where it may be more visible to the next person looking for help with the same problem.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by