필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Extracting entries from vector B that are best estimate each entry in vector A

조회 수: 1 (최근 30일)
C Meek
C Meek 2011년 1월 25일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi there.
I have two vectors, A & B.
A is of length 10, while B will always be of longer length (let's say 20 for this case).
I would like to extract the entries from B that best estimate each entry in A. Therefore, I want to finish up with B being of length 10.
Any help would be much appreciated!

답변 (2개)

Sean de Wolski
Sean de Wolski 2011년 1월 25일
A = 1.6:11;
B = 1:20;
[junk, idx] = min(bsxfun(@(x,y)abs(x-y),A.',B),[],2);
C = B(idx);

Bruno Luong
Bruno Luong 2011년 1월 25일
BS = sort(B);
C = interp1(BS, BS, A, 'nearest', 'extrap')
Bruno
  댓글 수: 1
Santosh Kasula
Santosh Kasula 2011년 1월 25일
Moving C Meek's comment from Answers section to here:
C Meek says: Thanks!

이 질문은 마감되었습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by