How to use discretize

2 次查看(过去 30 天)
shoki kobayashi
shoki kobayashi 2021-3-30
评论: dpb 2021-3-30
I am currently trying to use discretize to group data into bins.
I would like to group each column of a multi-dimensional data into a bin as if it is one data.
If I use the documentation method as is, the result is
>> a = rand(10):
>> [y, e] = discretize(a,3)
y =
3 1 2 2 2 1 2 3 1 1
3 3 1 1 1 2 1 1 3 1
1 3 3 1 2 2 2 3 2 2
3 2 3 1 2 1 2 1 2 2
2 3 2 1 1 1 3 3 3 3
1 1 2 3 2 2 3 1 1 1
1 2 2 2 2 3 2 1 2 2
2 3 1 1 2 1 1 1 2 2
3 2 2 3 2 2 1 2 1 1
3 3 1 1 2 1 1 2 2 1
e =
0 0.4000 0.8000 1.2000
.
I want to make it look like
y =
3
3
1
1
2
3
2
1
1
1
.
How can I do this?
  2 个评论
Steven Lord
Steven Lord 2021-3-30
rng default
A = rand(5)
A = 5×5
0.8147 0.0975 0.1576 0.1419 0.6557 0.9058 0.2785 0.9706 0.4218 0.0357 0.1270 0.5469 0.9572 0.9157 0.8491 0.9134 0.9575 0.4854 0.7922 0.9340 0.6324 0.9649 0.8003 0.9595 0.6787
[y, e] = discretize(A, 3)
y = 5×5
3 1 1 1 2 3 1 3 2 1 1 2 3 3 3 3 3 2 2 3 2 3 3 3 2
e = 1×4
0 0.4000 0.8000 1.2000
For this smaller example, what exactly would you want y to look like and how exactly would you compute that exected result? The more specifically you can explain how you would generate your grouping model the easier it will be for us to help you implement it.
dpb
dpb 2021-3-30
"... as if it is one data"
Maybe the idea is
>> [y,e]=discretize(A(:),3)
y =
3
3
1
3
2
1
1
2
3
3
1
3
3
2
3
1
2
3
2
3
2
1
3
3
2
e =
0 0.4000 0.8000 1.2000
>>
?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by