h = animatedline('Marker','o');

x = 1:5;

y = 1:5;

addpoints(h,x,y)


%======================================================================

pause
clc
clear all
close all



%======================================================================


h = animatedline;

axis([0 4*pi -1 1])

x = linspace(0,4*pi,2000);

for k = 1:length(x)

    y = sin(x(k));

    addpoints(h,x(k),y);

    drawnow

end




%======================================================================

pause
clc
clear all
close all



%======================================================================


h = animatedline;

axis([0 4*pi -1 1])

x = linspace(0,4*pi,2000);

for k = 1:length(x)

    y = sin(x(k));

    addpoints(h,x(k),y);

    drawnow limitrate

end

drawnow



%======================================================================

pause
clc
clear all
close all



%======================================================================

a1 = animatedline('Color',[0 .7 .7]);

a2 = animatedline('Color',[0 .5 .5]);

axis([0 20 -1 1])

x = linspace(0,20,10000);

for k = 1:length(x);

    % first line

    xk = x(k);

    ysin = sin(xk);

    addpoints(a1,xk,ysin);

    % second line

    ycos = cos(xk);

    addpoints(a2,xk,ycos);

    % update screen

    drawnow limitrate

end


%======================================================================

pause
clc
clear all
close all



%======================================================================

plot(rand(5))

F = getframe;

figure

imshow(F.cdata)


%======================================================================

pause
clc
clear all
close all



%======================================================================

Z = peaks;
figure('Renderer','zbuffer');
surf(Z);
axis tight;
set(gca,'NextPlot','replaceChildren');
for j = 1:20
    surf(sin(2*pi*j/20)*Z,Z)
    F(j) = getframe;
end
disp('now to the movie')
movie(F,20) % Play the movie twenty times

%======================================================================

pause
clc
clear all
close all



%======================================================================

figure

Z = peaks;

surf(Z)

axis tight manual

ax = gca;

ax.NextPlot = 'replaceChildren';

loops = 40;

F(loops) = struct('cdata',[],'colormap',[]);

for j = 1:loops

    X = sin(j*pi/10)*Z;

    surf(X,Z)

    drawnow

    F(j) = getframe;

end

% play movie twice

movie(F,2)

%======================================================================

pause
clc
clear all
close all



%======================================================================

v = VideoReader('xylophone.mp4');

while hasFrame(v)

    video = readFrame(v);

end

whos video

v.CurrentTime = 2.5;

currAxes = axes;

while hasFrame(v)

    vidFrame = readFrame(v);

    image(vidFrame, 'Parent', currAxes);

    currAxes.Visible = 'off';

    pause(1/v.FrameRate);

end


%======================================================================

pause
clc
clear all
close all



%======================================================================

v = VideoWriter('peaks.avi');

open(v);

Z = peaks;

surf(Z); 

axis tight manual 

set(gca,'nextplot','replacechildren'); 

for k = 1:20 

    surf(sin(2*pi*k/20)*Z,Z)

    frame = getframe;

    writeVideo(v,frame);

end

close(v);


%======================================================================

pause
clc
clear all
close all



%======================================================================

x=0:10:360;

y=sind(x);

theta=0;

while 1

    theta=theta+1;

    y_plot=y*sind(theta);

    plot(x,y_plot);

    axis([0,360,-1.2,1.2]);

    pause(0.001);

end

%======================================================================

pause
clc
clear all
close all



%======================================================================

x=linspace(0,1,100);

[X,Y] = meshgrid(x,x);

N=100; % Number of frames

for i = 1:N

    % Example of plot

    Z = sin(2*pi*(X-i/N)).*sin(2*pi*(Y-i/N));

    surf(X,Y,Z)

    % Store the frame

    M(i)=getframe(gcf); % leaving gcf out crops the frame in the movie.

end

movie(M)

movie2avi(M,'WaveMovie.avi');

%======================================================================

pause
clc
clear all
close all



%======================================================================

% Draw a sphere

sphere

% Make the current axis box square in size

axis('square') 

% Define title and labels for reference

title('Rotation of a sphere...')

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

% Modify azimuth (horizontal rotation) and update drawing

for az = -50 : .2 : 30

    view(az, 40)

    drawnow

end 

% Modify elevation (vertical rotation) and update drawing

for el = 40 : -.2 : -30

    view(30, el)

    drawnow

end

%======================================================================

pause
clc
clear all
close all



%======================================================================

% Define paraboloid

X = -2 : .1 : 2; Y = X;

[x, y] = meshgrid(X, Y);

z = .5 * (x.^2 + y.^2); 

% Draw 3D figure, keep track of its handle

h = surf(x,y,z);

% Keep axes constant

axis([-2 2 -2 2 0 20]) 

% Define title and labels for reference

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

% Stretch paraboloid and show updates

for i = 1 : .1 : 5;

    set(h, 'xdata', x, 'ydata', y, 'zdata', i*z)

    drawnow

    pause(.1)

end 

% Modify azimuth (horizontal rotation) and update drawing

for az = -37.5 : .5 : 30

    view(az, 30)

    drawnow

end 







