Binning a column vector to certain values (includes negative values)

2 次查看(过去 30 天)
Hello, I have a sey of X, Y coordinates that I am using for plotting a heatmap. My X & Y coordiantes are from a microscope stage and so vary slightly:
I move my stage in X&Y in steps of 500.
So my real data is typically:
X Y
0.1 0.2
-0.2 501
0.3 1000.5
-0.4 1502
-501 -0.1
-503 501
-500 1000.1
-499 1503
etc.
How can I make my data so both X & Y (both can be positive or negative) be binned into e.g.
X Y
0 0
0 500
0 1000
0 1500
-500 0
-500 1000
-500 1500
I tried the digitizer but it had NaN's in it,
data = [0 -0.2 -0.1 0 0.1 0 2 0.1 -0.1 0.2]
data =
0 -0.20 -0.10 0 0.10 0 2.00 0.10 -0.10 0.20
>> edges = 0:500:5000
edges =
0 500.00 1000.00 1500.00 2000.00 2500.00 3000.00 3500.00 4000.00 4500.00 5000.00
>> [Y,E] = discretize(data,edges)
Y =
1.00 NaN NaN 1.00 1.00 1.00 1.00 1.00 NaN 1.00
E =
0 500.00 1000.00 1500.00 2000.00 2500.00 3000.00 3500.00 4000.00 4500.00 5000.00

回答(1 个)

Steven Lord
Steven Lord 2019-9-12
The left edge of your first bin should be less than than the first value you want included in that bin. Right now, -0.2 doesn't fit into any of the bins; it's to the left of the first bin. If you change the first element of your edges vector to something less than -0.2 (as an extreme example that will guarantee everything smaller than 500 is in the first bin, use -Inf) it will include those negative values.
  1 个评论
Jason
Jason 2019-9-12
编辑:Jason 2019-9-12
So If I assume all my steps are about 500 and the max error in each could be +/- 5.
How would I go about defining the bins say from -10000 to 10000 with steps of -500 with an error of +/- 5 on each bin edge
so would want
-10005 to -9995 to be -10000
...
..
-5 to 5 to be 0
etc

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by