function A=rankdefmatrix(n,m)
% Q1 and Q2 orthogonal matrices %
A=randn(n,n);
[Q1,R]=qr(A);
A=randn(m,m);
[Q2,R]=qr(A);
D=zeros(n,m);
for ii=1:n
    for jj=1:m
        if ii==jj
            D(ii,jj)=randn;
        end
    end
end
x=randn;

for ii=1:n
    for jj=1:m
        if ii==jj
            if abs(D(ii,jj))<abs(x) % We put a random number of zeros in the diagonal of the D matrix 
            D(ii,jj)=0;
            end
        end
    end
end
A=Q1*D*Q2'; % Generation of a rank defecient matrix %
end
