Please how can I unstack a column of negative and positive values into 2 columns of positive and negative values respectively?
4 views (last 30 days)
dpb on 7 Jul 2016
p=sr(sr>0); % positive only
n=sr(sr<0); % negative only, you'll have to decide where zero goes if it exists...
ix=sr>0; % logical vector
n=sr(~ix); % eliminate the test once at expense of temporary variable
More Answers (1)
Jan Orwat on 7 Jul 2016
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);