19287

Animation process in Matlab

Question:

I am just learning how to use Matlab. The problem is animating simple 2D plots. In trying to animate a line from (0,0) to (0, 10) connecting them in an animation I have this so far:

x = 0; p = plot(x, y, 'o', 'EraseMode', 'none'); % p is the handle, for later manipulations axis equal for k = 0:1:10 % the idea here is to have k go from 0 to 10 and set y to that value y = k; set(p,'XData', x, 'YData', y) % then this adds another point based on that new y drawnow end

The problem is, when this is run, is that it only plots the first point. Any help appreciated.

Answer1:

You should draw a line define by two points, and then at each iteration update the y value of the second point:

h = plot([0 0],[0 0]); %// draw line initially axis([-1 1 0 10]) %// freeze axis to see how the line grows for k = 0:.1:10 set(h,'YData',[0 k]) %// update second y value drawnow end

Answer2:

MATLAB introduced a new way of animating lines, starting with version R2014b, called <a href="https://www.mathworks.com/help/matlab/ref/animatedline.html" rel="nofollow">animatedLine</a>.

Here's how you can use it to draw the vertical line in your question.

x = 0; h = animatedline(); set(gca,'ylim',[0 10],'xlim',[-5 5],'box','on'); for y=0:0.0001:10; addpoints(h,x,y); drawnow update end

Adjust the step size (0.001 in this example) to increase or decrease your animation speed as necessary. To get a set frames per second you will want to look into a timer callback instead.

Recommend

  • How can I ask matlab to give me the value of y if I input the value of x?
  • Image processing using MATLABR2010a
  • matplotlib Event Listeners Not Funcitoning In PyQT Widget
  • Saving a matlab figure and keeping all handles
  • Risks of RWX memory pages
  • Gnuplot plots incorrect time for time series plot
  • Remove weekend gaps in gnuplot for candlestick chart
  • Hough transform in MATLAB
  • Is it safe to accept URL parameters for populating the `url_for` method?
  • Iterate twice through a DataReader
  • Ember.js model to be organised as a tree structure
  • calculate gradient output for Theta update rule
  • How does document.ready work with angular element directives?
  • MongoDb aggregation
  • Use of this Javascript
  • C++ Partial template specialization - design simplification
  • Body moving without any force applied? (Box2d)
  • Paperclip, set path outside of rails root folder
  • Update CALayer sublayers immediately
  • How can I send an e-mail from a vbs script
  • Android screen density dpi vs ppi
  • How would I use PHP exceptions to define a redirect?
  • How to extract text from Word files using C#?
  • what is the difference between the asp.net mvc application and asp.net web application
  • How to get next/previous record number?
  • SVN: Merging two branches together
  • Invalid access key error using credentials redeemed from an amazon open id token
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • retrieve vertices with no linked edge in arangodb
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Python: how to group similar lists together in a list of lists?
  • How to set the response of a form post action to a iframe source?
  • Understanding cpu registers
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Change div Background jquery
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • need help with bizarre java.net.HttpURLConnection behavior
  • Qt: Run a script BEFORE make
  • Add sale price programmatically to product variations
  • reshape alternating columns in less time and using less memory