Histogram or similar plot to display point density of a 2d plot over time.

조회 수: 3 (최근 30일)
Hi everyone,
I have a 2D plot which consists of a certain number pf points, these points vary with time, but are located around a specific curve. I am currently using a scatter plot to represent the points with every iteration of time. As an example, the points at one time iteration are displayed in
the scatter plot like shown below.
i have all the points in time in a x-coordinate - time matrix, and y-coordinate - time matrix seperately. ie, every row is a new time interval, and every column is a point. is there a way to read all these points and display them as a histogram, which has the intensity corresponding to the number of times a point appears in a specific area in the plot.

채택된 답변

Jose Lara
Jose Lara 2016년 11월 29일
Since each iteration creates a new set of points, you will need to store all the values in a separate variable with the points you need. Take the script below as an example:
xt = zeros(2,10);
yt = zeros(2,10);
coords = zeros(100,2);
for i = 1:10
    for k = 1:10
        xt(1,k) = k;
        yt(1,k) = k;
        xt(2,k) = randi(10);
        yt(2,k) = randi(10);
        coords(k+(i-1)*10,:)= [xt(2,k) yt(2,k)];
    end
    figure
    plot(xt(2,:),yt(2,:),'o')
end
The variable 'coords' will have all the coordinates that have been used throughout the iterations. Since this histogram is dependent on 'x' and 'y', you will need to create a criteria in which this points might fall under and create what is called a 'Category'. For example, if you would like to have a point that is inside the circle x^2 +y^2 =9, you could do the following:
booleans = zeros(1,100);
for i = 1:100
    if coords(i,1)^2 + coords(i,2)^2 <= 9
        booleans(i) = 1;
    end
end
You can add other criteria in which you would like to divide the points. The 'histogram' function has the ability to take arguments that are Categories, which are categorical vector that can count how instances in a specific array as shown below:
histogram(booleans,[0 1],{'OutsideCircle','InsideCircle'})
The function will count which ones are inside and outside the circle and create a histogram with the name under the corresponding bar. For more information regarding Categories in the 'histogram' function, you may refer to the following link: http://www.mathworks.com/help/matlab/ref/histogram.html

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by