% 
% Draw the Lorenz attractor (3D) using the plot3 Matlab graphics command.
% The graphics object is created on the fly via an iterative process.
% This script is a modified version of the script in the Matlab User's Guide
% Graphics Tutorial.
%
clear
figure

A = [-8/3 0 0; 0 -10 10; 0 28 -1];
b = [35 -10 -7]';
h = 0.01;

%
% Initialize the graphics object
%
mobj = plot3( b(1), b(2), b(3), 'EraseMode', 'none' );
axis( [0 50 -25 25 -25 25] );

xlabel('x');
ylabel('y');

hold on

%
% Create an animation effect in Matlab by using a for loop.
%
for i = 1:2500

  A(1,3) = b(2);
  A(3,1) = -b(2);
  bdot = A*b;
  b = b + h*bdot;

  %
  % Modify a graphics object on the fly using the 'set' command 
  % and 'Data' arguments to update one single point x,y,z value.
  % Store the x,y,z data in arrays xd,yd,zd indexed by i.  
  %  
  set( mobj, 'XData', b(1), 'YData', b(2), 'ZData', b(3) );
  
  xd(i) = b(1);
  yd(i) = b(2);
  zd(i) = b(3);
  
  drawnow
end

%
% Update the object with the data arrays which store all the points.
% Send the entire object to Geomview.
%
set( mobj, 'XData', xd, 'YData', yd, 'ZData', zd );
geomview( mobj );

