appending data to scatter(x,y)
38 次查看(过去 30 天)
显示 更早的评论
I am n random points in two dimensional space (x,y). I am using scatter(x,y) to visualize them.
Now I want to take the center of mass of these points (x,y) with a formula, and now I want to append them to the scatter(x,y). There are now n+1 points. How do I do this, aside from using 'hold on'?
Your insights would be great
0 个评论
采纳的回答
Robert Dylans
2015-10-8
"Center of mass" makes me hesitate a bit on this. Might want to clarify exactly what you mean by that. Do you want to connect the points in order, forming a closed shape, and calculate centroid from that? Or just use averages to find the center of the data points themselves? Or find the center of the outer bounds of the data, directly between min&max?
Assuming the second option above:
x=[0,1,1.5,3,5];
y=[5,3,1.5,1,0];
scatter(x,y);
c=[mean(x),mean(y)];
hold on;
scatter(c(1),c(2));
hold off;
This only appends the center (c) to the plot, not to the data (x,y). To do that,
x=[x c(1)];
y=[y c(2)];
0 个评论
更多回答(1 个)
Will Reeves
2022-3-16
编辑:Will Reeves
2022-3-16
I would like to add scatter points to a plot during a loop to visualise the process I'm running.
I currently use hold on, and scatter the new point every time it's created, or destroyed. Unfortunately, the way Matlab handles (excuse the pun) scatter plots is fine if you are scattering a large number of points at once. If you're scattering one point at a time it eats memory like a monster if you have a few thousand individual scatter points. (I got to 20GB quickly then my PC ground to a stop!).
It would be lovely to have a feature where you can add data to a dataset or scatter plot and have it "add" the point, rather than creating a whole new object. For instance
sp=scatter(data(:,1),data(:,2));
then add a point to the data, then
sp.update
or something?
Of course this leads to another issue in Matlab whereby "adding extra points to arrays" is horrifically slow, and pre-allocation is fine if you already know the outcome. It would be lovely to have the "list functionality" that other languages have where you can efficiently add data to a list without reallocation - obviously a list object wouldn't be as fast at other types of computation though appreciated.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!