필터 지우기
필터 지우기

How to sort out negative and positive values of a vector?

조회 수: 10 (최근 30일)
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar 2018년 10월 10일
편집: madhan ravi 2018년 10월 10일
if A= -3 -2 -1 0 1 2 3 i want to sort the negative values and positive values in a separate vector

채택된 답변

madhan ravi
madhan ravi 2018년 10월 10일
편집: madhan ravi 2018년 10월 10일
A=[ -3 -2 -1 0 1 2 3 ]
Negative_nos = sort(A(A<0))
Positive_nos = sort(A(A>=0))
Will do the trick
  댓글 수: 2
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar 2018년 10월 10일
what sould i do i wanrt to sort only first two values and last three values separately?
madhan ravi
madhan ravi 2018년 10월 10일
편집: madhan ravi 2018년 10월 10일
sort(A(1:2)) %first two
sort(A(end-2:end)) %last three
give a vote if you find it useful

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by