function U = clGS(V)
% Classical Gram-Schmidt
% Input  : V - nxq (n >= q)
% Output : U - nxq, has orthonormal columns s.t. Col(U) = Col(V)

[~,q] = size(V);

for j = 1:q
    
    U(:,j) = V(:,j);
    
    for k = 1:j-1
        U(:,j) = U(:,j) -  (U(:,k)'*V(:,j))*U(:,k);
    end
    
    U(:,j) = U(:,j) / norm(U(:,j));

end

return;

