MATLAB: How to sort out negative and positive values of a vector loopmathematical if A= -3 -2 -1 0 1 2 3 i want to sort the negative values and positive values in a separate vector Best Answer A=[ -3 -2 -1 0 1 2 3 ]Negative_nos = sort(A(A<0))Positive_nos = sort(A(A>=0))Will do the trick Related SolutionsMATLAB: How to create a vector of this output Try this: [X,Y,Z] = ndgrid(-2:2);Out = [Z(:),Y(:),X(:)]producing: Out = -2 -2 -2 -2 -2 -1 -2 -2 0 -2 -2 1 -2 -2 2 -2 -1 -2 -2 -1 -1 -2 -1 0 -2 -1 1 -2 -1 2 -2 0 -2 -2 0 -1 -2 0 0 -2 0 1 -2 0 2 etc. MATLAB: Sorting through labelled data str = { '0,Negative' '1,Negative' '1,Positive' '2,Negative' '2,Positive' '3,Positive' '4,Negative' '4,Positive' '5,Positive' '9,Positive'} ;% Get positive idx = contains(str,'Positive') ; str(idx) Related QuestionHow to make a matrix with all possible combinationAveraging positive and negative values seperately for each array in a matrixChange specific matrix values to negatives
Best Answer