how to find n values that are closest to zero

3 visualizaciones (últimos 30 días)
studentambitious
studentambitious el 26 de Abr. de 2016
Comentada: studentambitious el 27 de Abr. de 2016
I have a matrix of 50 x 50 with floating point values both positive and negative signs...i want to find n values lying on both sides that are closest to zero along with their indices ... please help

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 26 de Abr. de 2016
Editada: Azzi Abdelmalek el 26 de Abr. de 2016
Look at this example: A is a matrix 5x5 and n=2
A=rand(5)-0.5
n=2
[~,idx]=sort(abs(A(:)))
B=A(idx)
[ii,jj]=ind2sub(size(A),idx(1:n))
out=[B(1:n) ii jj]
  4 comentarios
studentambitious
studentambitious el 26 de Abr. de 2016
Thanks Walter
studentambitious
studentambitious el 27 de Abr. de 2016
can we replace ~ in line [~, idx]=sort(abs(A(:))) with some other name???? how this NOT (~) symbol works here

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Annotations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by