# Matlab - area values into raster data

1. Aug 5, 2013

### MartinV

I'm trying to transform area values into raster data.

I have areas, defined as circles (location of center + length of radius). Each area has a designated value between 0 and 2. I used Matlab's command area to plot the areas and also to designate the value that goes with each area. Now I want to transport this into raster data so I can plot it using pcolor.

When my areas were squares, I could simply type this:
Net(-1*(Loc(1,2)-50)/10*L+1:-1*(Loc(1,2)-50)/10*L+L/2^2+1, (Loc(1,1)+82)/10*L+1:(Loc(1,1)+82)/10*L +L/2^2+1) = Data3(1,2);

The pixels in Net were designated with the value from Data3 but there should be a more elegant way to do this with Matlab, I just don't know what it is.

Any suggestions?

2. Aug 5, 2013

3. Aug 6, 2013

### MartinV

This doesn't look like it has anything to do with what I'm trying to do. Maybe I need to try explaining it again.

I have a dataset of events that have geographical coordinates and a magnitude. The location plot looks like this:

Some areas are very densely populated, some are sparsely. To get the feel of the magnitude of these events, I've made a grid and put each event into its own pixel. The pcolor function gives me this color-coded plot:

Again, the spatial sparcity of the events works against me as most of the picture is just grey (0 value). So the idea was to assign areas and come up with an average magnitude for that area that all events in that area contribute into. The first idea was to use squares; using pcolor for color-coding this is what came up:

This plot lacked fluency so I used interpolation to make the transition between areas smoother. This is what I got, again using pcolor function:

Now I realized that the boxiness of the areas felt false so I abandoned square areas and went to circles. This are the circles I designated:

Each circle has its magnitude assigned, now I want to put those values down into a matrix so I can use pcolor again in hope that it will look like the over-boxy color-coded picture above.

Since this is all geographically based, I need to plot that final color-coded plot on top of a map but that comes later.

4. Aug 7, 2013

### Pythagorean

1) Are the circles (a) a sampled region in which you count the number of events (and that's your magnitude) or (b) is the magnitude encoded in the size of the circles?

2) If a), how do you interpret overlap then? Aren't you counting events more than once where there's overlap?

5. Aug 7, 2013

### MartinV

Yes, circles overlap and some events are taken multiple times. I intend to draw the big circles first and then smaller on top of them so the values of pixels would be overwritten.

6. Aug 8, 2013

### Pythagorean

That's one wants to implement it. I think there's a better way, though

Another question. In your original pcolor image, what do the magnitude (color) of individual points represent? Are events not binary?

7. Aug 8, 2013

### MartinV

All events have a magnitude with values the colorbar shows. The color coding represents that magnitude.

My point is that making squares in a matrix is easy because Matlab's way of assigning values to elements makes it natural A(123:321,123:321) = 2. This instantly makes a square. Right now I'm tryin to do it by using a statement like this:

sqrt((x0 - x).^2 + (y0 - x).^2) <= R;

However, I have to use a loop in a loop to go through all rows and columns, assigning value to each element. since this is a 1000×1000 matrix and I have 136 circles to mount, this might take a long time.

Is there a more elegant way than what I just described?

Last edited: Aug 8, 2013