Please how can I unstack a column of negative and positive values into 2 columns of positive and negative values respectively?
조회 수: 2 (최근 30일)
이전 댓글 표시
sr=[-34;45;28;-10;-9]. s=sign(sr). I want to obtain sr1=[-34;-10;-9] and sr2=[45;28]
댓글 수: 0
채택된 답변
dpb
2016년 7월 7일
p=sr(sr>0); % positive only
n=sr(sr<0); % negative only, you'll have to decide where zero goes if it exists...
or,
ix=sr>0; % logical vector
p=sr(ix);
n=sr(~ix); % eliminate the test once at expense of temporary variable
추가 답변 (1개)
Jan Orwat
2016년 7월 7일
You can compare your data with zero. This will classify your data and you can use it to get what you want.
Example based on your example data:
sr = [-34;45;28;-10;-9];
positive = (sr >= 0);
sr1 = sr(~positive); % ~ in Matlab represents negation
sr2 = sr(positive);
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!