Find an array element's index
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a first array that has about 5000 values. I have a second array that is (first array - (0.3)*(first array(1))); For every element in the first array, I must find the value and index of the closest element in the second array. Any help is highly appreciated.
댓글 수: 1
Jan
2017년 10월 2일
What have you tried so far? Is this a homework? Did you search in the forum already?
답변 (2개)
Image Analyst
2017년 10월 2일
Did you try the obvious min() function????
[closestValue, indexOfClosestValue] = min(abs(array1-array2));
Make sure array1 and array2 are not uint8 or uint16 though. Cast to double first, if you're using one of them.
댓글 수: 0
A VP
2017년 10월 5일
댓글 수: 1
Image Analyst
2017년 10월 5일
But your temp is always a constant. Since y = x-constant, then y-x is x-(x-constant) which equals the constant. So it's the same everywhere. All elements have the same value, which is 0.3*x(1).
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!