Advice Grid Point Position Advice

3 views (last 30 days)
Si on 19 Sep 2013
Hi, (firstly apologies for the title. Not sure how to describe this).
I am after some advice/help.
ABOUT: I have a text file which contains approx. 100,000 lines. On each line there are 2 values. One represents an x co-ordinate, the other y co-ordinate.
e.g. of a line entry)
0.4343211, 1.2133457
Each x, y pair represents a point on a square. The square is of size A * A. The range of values an x or y co-ordinate can have is between -A and +A.
AIM: If I overlay the square with an imaginary grid, I want to produce a plot of where these x, y positions are on the grid and how many there are in each locality. The size of the grid is not definite. It could be 100 * 100 or 800 * 800. But ultimately I would want to gather information pertaining to how many of the x,y points fall into each grid box and then illustrate this with a plot.
I would like a plot which uses a color scale to show the amount of points that lie in each grid. e.g.) Blue might represent less than 100 and on the other end of the scale red may represent more than 1000.
I am still considering my options as to how I will implement this but would value advice.

Accepted Answer

Kelly Kearney
Kelly Kearney on 19 Sep 2013
I think what you're looking for is a 2D histogram:
% Data
x = randn(1000,1);
y = randn(1000,1);
% Bin edges
xedge = linspace(-3, 3, 10);
yedge = linspace(-3, 3, 10);
% Histogram
n = hist3([x y], 'edges', {xedge yedge});
% Plot results
pcolor(xedge, yedge, n);
hold on;
plot(x, y, 'k.');
(Note that I'm using the edges option in hist3... hist3 allows you to specify the bin centers instead if that's more relevant to your problem).

More Answers (0)


Community Treasure Hunt

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

Start Hunting!