Matlab - area values into raster data

  • Context: MATLAB 
  • Thread starter Thread starter MartinV
  • Start date Start date
  • Tags Tags
    Area Data Matlab
Click For Summary

Discussion Overview

The discussion revolves around transforming area values, specifically defined as circles, into raster data for visualization in Matlab. Participants explore methods for efficiently assigning values to a matrix based on the circular areas, with a focus on improving the elegance and performance of the code used for this task.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant describes their approach using Matlab's area command to plot circles and assign values, seeking a more efficient method to convert this into raster data for pcolor plotting.
  • Another participant suggests the use of the accumarray function, although they express uncertainty about its relevance to the original problem.
  • A participant elaborates on their dataset, explaining the geographical context and the need for a smoother representation of event magnitudes using circles instead of squares.
  • Questions are raised about how to handle overlapping circles and whether the magnitude is represented by the size of the circles or by counting events within them.
  • One participant indicates their intention to layer circles, suggesting that larger circles will overwrite the values of smaller ones in the raster data.
  • Concerns are expressed about the efficiency of using nested loops to assign values to a large matrix for multiple circles, prompting a search for a more elegant solution.

Areas of Agreement / Disagreement

Participants express differing views on the best approach to implement the rasterization of circular areas, with no consensus reached on a single method. There is also uncertainty regarding the interpretation of overlapping circles and their impact on magnitude calculations.

Contextual Notes

Participants mention the computational challenges associated with processing a large matrix (1000×1000) and multiple circles (136), highlighting the potential inefficiencies of their current methods without resolving these issues.

MartinV
Messages
68
Reaction score
0
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?
 
Physics news on Phys.org
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:
MainPlot_zps6d0eedd8.png


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:

ColorCodedMap250_zpsf5ac5723.png


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:

ColormapTest_zps98decef2.png


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

InterpTest2_zps0b0118da.png


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:

CircleTest1_zpsf8e5547e.png


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.
 
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?
 
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.
 
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?
 
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:

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
1
Views
3K
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K