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

4 ビュー (過去 30 日間)
Craig Kavan Pinto
Craig Kavan Pinto 2016 年 11 月 21 日
回答済み: Jose Lara 2016 年 11 月 29 日
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 Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by