How to determine how many data points are in a scatter plot?
Show older comments
I have scatter plots in .fig format. They open in matlab without a problem. Most of the relevant statistics like mean, std, etc., can be found in the figure window under TOOLS > DATA STATISTICS, except for the number of datapoints. Anyone know where this is hiding? Thanks.
Answers (1)
Star Strider
on 1 Jul 2019
It is only slightly hidden.
Try this:
figure
scatter(rand(1,10), rand(1,10))
Ax = gca;
hs = findobj(gca, 'Type','scatter')
NrPoints = numel(hs.XData);
Your figure must be open in your workspace. The ‘hs’ output will return the number of scatter objects in your axes, so you may need to do ‘NrPoints’ for each scatter object.
If you have more than one, subscript ‘hs’ to get each one:
figure
scatter(rand(1,10), rand(1,10))
hold on
scatter(rand(1,20), rand(1,20))
hold off
Ax = gca;
hs = findobj(gca, 'Type','scatter')
NrPoints = numel(hs(1).XData);
This works the same way for your .fig files as for this example.
1 Comment
z8080
on 12 Nov 2020
Any idea how the number of data points per category can be extracted when the plot is made with gramm toolbox, thus not an actual scatter object?
Categories
Find more on Scatter Plots 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!