Grouping data by value
Show older comments
Hi. I have 432x1 data. I need to grouping the data.
for example;
-0.989088822111364
-1.16881053159657
-0.687960193675098
0.609028518151482
0.853112207247799
1.09867863373770
0.325581735572437
-0.358624505229866
-0.116184636997357
-1.12249570113502
-0.878711918410750
-0.843582079603111
-0.763107095944730
-0.963235098445007
-1.36135857090159
-1.93513836539865
-1.53179202986538
-1.24445835422832
0.643855927191538
0.506078478817649
1.10211477120999
0.119654919704736
-0.186087379373470
0.208608204079503
0.542441939121425
1.09907331469601
0.595582967612814
0.605674642059506
-0.0429774937224157
How can I assign them to groups such as:
moderate= -1.00 to -1.49
severe= -1.50 to -1.99
Accepted Answer
More Answers (1)
discretize() with boundaries and 'categorical' and a list of category names.
data = [
-0.989088822111364
-1.16881053159657
-0.687960193675098
0.609028518151482
0.853112207247799
1.09867863373770
0.325581735572437
-0.358624505229866
-0.116184636997357
-1.12249570113502
-0.878711918410750
-0.843582079603111
-0.763107095944730
-0.963235098445007
-1.36135857090159
-1.93513836539865
-1.53179202986538
-1.24445835422832
0.643855927191538
0.506078478817649
1.10211477120999
0.119654919704736
-0.186087379373470
0.208608204079503
0.542441939121425
1.09907331469601
0.595582967612814
0.605674642059506
-0.0429774937224157];
cats = discretize(data, [-1.99, -1.50, -1, 1, 1.5, 1.99], 'categorical', {'severe', 'moderate', 'nomimal', 'good', 'excellent'})
Categories
Find more on Categorical Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!