Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Plot animation with Struct. Variables

Asked by Lawson Hoover

Lawson Hoover (view profile)

on 8 Dec 2012
Latest activity Commented on by Lauren

Lauren (view profile)

on 13 Dec 2013

I was trying to turn this sequence for a single plot into a movie. Beam.x and Beam.y is a 100 spot vector. My original code is:

   plot(x,y,'--r','LineWidth',3);                      % This is the original position of the Beam 
  hold on                                             % Holds only the axes values                                         
  line(Beam.x,Beam.y,'color','b','linewidth',2);      % The New position of Beam
  xlabel('Beam Length (in.)','Color','g');
  ylabel(bstr,'Color','g');
  ylim([-(Beam.y(10)) max(Beam.y)]);
  legend('Without Deflection','With Deflection');
  title(astr,'Color','y','fontweight','b');
  set(S.ax,'YDir','reverse');
  set(S.ax,'XGrid','on');
  set(S.ax,'YGrid','on');  
  hold off 

Anytime I try to turn it into a movie or anything of the sort I get the error:

The following error occurred converting from struct to double:
Error using double
Conversion to double from struct is not possible.

OR:

Error using capturescreen
Figure destroyed during getframe
Error in getframe (line 103)
     x=builtin('capturescreen', varargin{:});

Any ideas?

2 Comments

Walter Roberson

Walter Roberson (view profile)

on 8 Dec 2012

Which line of code shows the problem about converting struct to double? How are you trying to turn it into a movie?

Lawson Hoover

Lawson Hoover (view profile)

on 8 Dec 2012
   % Data 
  clear; close all;
  M = zeros(1,100);
  x = linspace(1,100);
  y = linspace(50,100);
  % figre
  figure(1);
  set(gcf,'Renderer','OpenGL');
  h = plot(x(1),y(1),'-r','linewidth',6);
  set(h,'EraseMode','normal');
  % Animation 
  j = 1;
  for j = 1:100
      set(h,'XData',x(j))
      set(h,'YData',y(j))
      plot(h)
      M(j) = getframe;
  end
movie(M,2)

The Code above is what I have been messing with to figure the animation thing and it keeps on returning the first error.

Lawson Hoover

Lawson Hoover (view profile)

Products

No products are associated with this question.

1 Answer

Answer by Lawson Hoover

Lawson Hoover (view profile)

on 8 Dec 2012
Accepted answer

I have figured out how to make it work.

1 Comment

Lauren

Lauren (view profile)

on 13 Dec 2013

Can you please share? I am having the same problem. How did you get it to work?

Lawson Hoover

Lawson Hoover (view profile)

Contact us