how to find n values that are closest to zero

조회 수: 5 (최근 30일)
studentambitious
studentambitious 2016년 4월 26일
댓글: studentambitious 2016년 4월 27일
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월 26일
Thanks Walter
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