How do I get the closest values of an array stored for a particular input ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Raahul Palanivel Uma
el 17 de Ag. de 2016
Comentada: Azzi Abdelmalek
el 17 de Ag. de 2016
Hello all,
I have an array A = [180 170 160 150 140 130] and b = 165... how do I determine the closest positions and values of b from A i.e. what function should I use to get the answer as 170 & 160.
Thank you for your help in advance.
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 17 de Ag. de 2016
Editada: Azzi Abdelmalek
el 17 de Ag. de 2016
A = [180 170 160 150 140 130]
b=165
a1=min(A(A>b))
a2=max(A(A<b))
Más respuestas (1)
Thorsten
el 17 de Ag. de 2016
[~, ind]= sort(abs(A-b));
A(ind(1:2))
2 comentarios
Azzi Abdelmalek
el 17 de Ag. de 2016
It doesn't work for this example
A = [180 170 162 161 150 140 130]
b=165
[~, ind]= sort(abs(A-b));
A(ind(1:2))
The result is
162 161
Ver también
Categorías
Más información sobre Logical 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!