Please how can I unstack a column of negative and positive values into 2 columns of positive and negative values respectively?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nadousse28
am 7 Jul. 2016
Kommentiert: Nadousse28
am 8 Jul. 2016
sr=[-34;45;28;-10;-9]. s=sign(sr). I want to obtain sr1=[-34;-10;-9] and sr2=[45;28]
0 Kommentare
Akzeptierte Antwort
dpb
am 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...
or,
ix=sr>0; % logical vector
p=sr(ix);
n=sr(~ix); % eliminate the test once at expense of temporary variable
Weitere Antworten (1)
Jan Orwat
am 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);
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!