A=load('lena512.mat');%load the picture %in Matlab this returns a struct variable A=A.lena512;%we only need the matrix field, so we can simply overwrite the A variable %now A is matrix containing numbers from 0 to 255 %to get a greyscale image, we can use %colormap command, which takes as its argument %a matrix that determines RGB components for indexed colors scale=linspace(0,1,255); colormap([scale;scale;scale]'); figure(1); image(A);%produce the image [U,S,V]=svd(A);%the svd decompostion %the matrix S contains the singular values on the diagonal in descending order s=diag(S);%extracting the diagonal into a column vector for n=[10 20 50 100]%for selected values of n figure(n); An=U(:,1:n)*S(1:n,1:n)*V(:,1:n)';%we form an approximation %of A using only the n largest singular values image(round(An)); end