Moving points on a graph?

조회 수: 6 (최근 30일)
Bear12
Bear12 2016년 1월 9일
답변: Walter Roberson 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