Grouping data by value
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
KSSV
2021-2-8
Let x be your data. Create arespective y-value which denotes grouping.
y = zeros(size(x)) ;
% get values -1.00 to -1.49
idx = x >= -1 && x < -1.49 ;
y(idx) = 1 ; % say one stand for moderate
% get values between -1.50 and -1.99
idx = x >= -1.50 && x < -1.99 ;
y(idx) = 2 ; % say two stand for
0 个评论
更多回答(1 个)
Walter Roberson
2021-2-8
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'})
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!