How to create a %of time vs %of area plot

2 views (last 30 days)
Dear all,
I have the matrix A(1000x1000x120) which represents noise levels arranged as (longitude x latitude x time).
I want now to create a plot like the following one:
This plot represents the percentage of time that a specific noise level is exceeded in a percentage of area.
Can you give me some ideias how this can be done?
Thank you in advance,
RD

Accepted Answer

Benjamin Kraus
Benjamin Kraus on 1 Feb 2022
There are a lot of missing details from your question that would need to be filled-in before someone can provide a good answer.
  1. How are you calculating area? You have latitude and longitude, and distance (and thus area) is not linear with latitude and longitude. You didn't indicate that you had a separate matrix that stores the actual latitude and longitude values. Does that mean you are OK assuming that a 1x1 square in latitude/longitude is a uniform area or do you want to take into account the actual latitude and longitude values? To do the latter, you likely will need the Mapping Toolbox to do the correct area calculations.
  2. Are your 1000x1000 locations a uniform grid of locations, or are they a random collection of 1 million data points. In other words, can you simply count the number of values above the noise threshold to get an approximation of area, or do you need to take into account that some data points represent larger areas than others?
  3. I assume you are interested in what percentage of time a single point exceeds the noise threshold, but that isn't specified. Imagine an ambulance driving down the street as the single source of noise, and the volume of the ambulance is such that it causes an area equal to 10% of your test area to exceed the threshold. At any one point in time the same area will exceed the noise threshold (10%), but that area will move, so one specific location may only exceed the noise threshold for a short time window. In that example, your graph could have a single point at 10% area for 100% of the time. Or, because the ambulance is moving, it could have a single point at 10% area at a much lower %time because any specific location only exceeded the threshold for a short time. I assume you want the later, not the former.
Making some assumptions, here is one idea:
I start with some random data, assuming a uniform grid of points, such that each data point represents a uniform amount of area. I have no idea what scale you are working on, so I'll just assume 0 to 1, and I'll pick an arbitrary threshold of 0.5.
noise = rand(1000,1000,120);
threshold = 0.5;
Now I want to find out what data values exceed the threshold. That is easy:
tooNoisy = noise >= threshold;
That gives a logical matrix (true/false) indicating whether each location exceeded the threshold at each point in time. Now I want to find out for how much time each point exceeded the threshold, so I'll simply sum in the third dimension, and convert into a percentage:
n = size(tooNoisy,3);
timeAboveThreshold = sum(tooNoisy,3)*100/n;
Now you want to find out how many points had each different timeAboveThreshold. There are a variety of ways to do this in MATLAB. My personal favorite is accumarray, but a lot of people find accumarray challinging to use, so instead I'll use histcounts. In addition, because you have 120 time points, you can have up to 120 unique values in your timeAboveThreshold matrix, so I'm just going to treat each unique value as distinct. If you had more time values, you may want to adjust the bin sizes, or let histcounts pick the bins for you.
% Create "edges" that surround each unique value.
centers = 100*(0:n)/n;
edges = 100*(-0.5:(n+0.5))/n;
N = histcounts(timeAboveThreshold(:),edges);
Now, assuming each data point represents a uniform area, you need to divide by the number of data points to get to percentage of area.
percentArea = N./(size(tooNoisy,1).*size(tooNoisy,2));
area(centers, percentArea)
hold on
plot(centers, percentArea, 'r*')
Of course, this is random fabricated data, so a bell-curve seems just about right.
  6 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!