Find adjacent values of a vector corresponding to another vector
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
anton fernando
el 21 de Dic. de 2017
Respondida: Jos (10584)
el 22 de Dic. de 2017
Hi, I am trying to find the adjacent points of a 1-D vector corresponding to the elements of another column vector. It is very hard to explain. I will explain it from an example.
A=[ 11; 22; 32; 44; 51;]; B=[11.4 32.4 36.6]; So I need a matrix with the adjacent points of each element of the vector B of vector A as in, Ans1=[11 22; 32 44; 32 44;] also the corresponding locations as in, ans2[1 2; 3 4; 3 4;] Appreciate any help.
0 comentarios
Respuesta aceptada
Matt J
el 21 de Dic. de 2017
idx=discretize(B,A);
Ans2=[idx(:),idx(:)+1];
Ans1=A(Ans2);
7 comentarios
Más respuestas (1)
Jos (10584)
el 22 de Dic. de 2017
Here is a solution that finds the element in A that is just before or just after each element in B.
A=[ 11; 22; 32; 44; 51;]; B=[11.4 32.4 36.6]
clear ans2
ans2(:,1) = nearestpoint(B, A, 'before') ;
ans2(:,2) = nearestpoint(B, A, 'after') ;
ans1 = A(ans2) % will fail when elements of B do not fall between elements of A. Check for that!
My NEARESTPOINT utility can be downloaded from the File Exchange:
0 comentarios
Ver también
Categorías
Más información sobre Large Files and Big Data en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!