Binning a column vector to certain values (includes negative values)
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Steven Lord
el 12 de Sept. de 2019
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 comentario
Ver también
Categorías
Más información sobre Data Distribution Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!