%
% Application Programming in MatLab-environment
% Autumn 2000
% 
% Exercise 3 & 4
%

% Clear the variables and close all windows
clear
close all

% ----- Problem 5 -----
% animation of matrix A when the given function is 
% applied consecutively to the entries of the matrix
A = rand(4,4)
N = 10;

% using EraseMode property
hr = matrix_graph(A,'r','*');
set(hr,'EraseMode','xor');

for i=1:N
   for k=1:length(hr)
      y = get(hr(k),'YData').^2;
      set(hr(k),'YData',y);
   end
   disp('Press any key.'); pause
end

close all

% using movie functions
% getframe returns a pixmap of the current axis,
% so we cannot use it to create animations of figures with
% several axes. We have now only one axis in the figure.
A = rand(1,6);
hr = matrix_graph(A,'r','*');
M = moviein(N);

for i=1:N
   for k=1:length(hr)
      y = get(hr(k),'YData').^2;
      set(hr(k),'YData',y);
   end
   M(:,i) = getframe;
end

disp('Starting the movie. Press any key.'); pause
movie(M,2,3)

close all
clear all

% ----- Problem 6 -----
load clown
whos
x_min=min(min(X));
x_max=max(max(X));
inds=x_min:4:x_max;

f1=figure;
subplot(1,2,1)
image(X)
axis square
colorbar
%
subplot(1,2,2)
amap=get(f1,'Colormap');
b=bar(amap(inds,:));
axis square
set(b(1),'FaceColor','r')
set(b(2),'FaceColor','g')
set(b(3),'FaceColor','b')
title('RGB-values of the default colormap')

disp('Press any key.'); pause
%
f2=figure;
subplot(1,2,1)
image(X)
colormap(map)
axis square
colorbar
subplot(1,2,2)
b=bar(map(inds,:));
axis square
set(b(1),'FaceColor','r')
set(b(2),'FaceColor','g')
set(b(3),'FaceColor','b')
title('RGB-values of the pictures own colormap')

return
