Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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

2 visualizaciones (últimos 30 días)
C Meek
C Meek el 25 de En. de 2011
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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!

Respuestas (2)

Sean de Wolski
Sean de Wolski el 25 de En. de 2011
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 el 25 de En. de 2011
BS = sort(B);
C = interp1(BS, BS, A, 'nearest', 'extrap')
Bruno
  1 comentario
Santosh Kasula
Santosh Kasula el 25 de En. de 2011
Moving C Meek's comment from Answers section to here:
C Meek says: Thanks!

La pregunta está cerrada.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by