function svdhello
% SVDHELLO shows "image compression" using SVD

A = hello;      % generates matrix A
close all       % eliminates figure generated by hello.m

subplot(3,3,1), spy(A,'ko')
set(gca,'XTick',[]),  set(gca,'YTick',[])
title('spy(HELLO)')
showit(2,A),  title('HELLO as an image')

% use SVD for various "compressions"
[U,S,V] = svd(A);
c=7;  showit(3,U(:,1:c)*S(1:c,1:c)*V(:,1:c)')
title('rank 7 approx')
c=5;  showit(4,U(:,1:c)*S(1:c,1:c)*V(:,1:c)')
title('rank 5 approx')
c=3;  showit(5,U(:,1:c)*S(1:c,1:c)*V(:,1:c)')
title('rank 3 approx')
c=2;  showit(6,U(:,1:c)*S(1:c,1:c)*V(:,1:c)')
title('rank 2 approx')
c=1;  showit(7,U(:,1:c)*S(1:c,1:c)*V(:,1:c)')
title('rank 1 approx')
c=2;  showit(8,U(:,c)*S(c,c)*V(:,c)'),  title('\sigma_2 u_2 v_2*')
c=3;  showit(9,U(:,c)*S(c,c)*V(:,c)'),  title('\sigma_3 u_3 v_3*')

  function showit(pos,B);                % helper function
  subplot(3,3,pos)
  imagesc(B),  colormap gray   % or use pcolor()
  axis([1 40 1 15]),  set(gca,'XTick',[]),  set(gca,'YTick',[])
  end
end
