how to find n values that are closest to zero

1 次查看(过去 30 天)
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

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2016-4-26
编辑:Azzi Abdelmalek 2016-4-26
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 个评论
studentambitious
studentambitious 2016-4-27
can we replace ~ in line [~, idx]=sort(abs(A(:))) with some other name???? how this NOT (~) symbol works here

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by