Moving points on a graph?

6 次查看(过去 30 天)
Bear12
Bear12 2016-1-9
Hi (I'm sort of new to Matlab) - I'm having a lot of trouble plotting (n=10) points on a graph to move randomly on a graph. I know how to plot them, but making them move about is what is stumping me. Any assistance would help greatly!
Just in case I wasn't very specific haha I created a gif on Photoshop to kind of clear things up:
Basically what I am trying to eventually do is that there are two diffrent types of dots: Black dots are 'piggies' or 'prey' and the Red dots are 'birds' or 'predators.' As the "Birds" eat these "Piggies" you can notice they increase in size. You will also notice the "Piggies" just move in randomly spots on the graph while the "Birds" try to chase them down.
Thanks!

回答(2 个)

Les Beckham
Les Beckham 2016-1-9
If you search the Matlab File Exchange for 'game of life' you will find many implementations of a predator/prey 'simulation' that may give you inspiration.
In general, the way to update points on a graph is to update the 'Xdata' and 'Ydata' for the existing line object(s). Check the docs for line properties.
Good luck.

Walter Roberson
Walter Roberson 2016-1-9
If you have R2014b or later you can use animatedline(); see http://uk.mathworks.com/matlabcentral/answers/263148-delete-points-after-a-certian-i
However, animatedline() would not allow for different marker sizes.
To support different marker sizes for different points, use scatter(). Once you create the scatterseries object, you can set its XData, YData and SizeData properties

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by