You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: igls_orig.m
    path of file: ./repos/CanlabCore/CanlabCore/Statistics_tools/Iterative_Generalized_Least_Squares
    
    the code of the file until where you have to start completion: function [beta,betastar] = igls_orig(y, x, Vy, type)
% function [betastar] = igls(y, x, 
    
function V = vech(Mat)
% function V = vech(Mat)
%
% Calculate vech for the matrix Mat
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

V = Mat(logical(tril(ones(size(Mat)))));

return;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function Mat = ivech(V)
% function Mat = vech(V)
%
% Calculate the "inverse" of the vech function
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

len = length(V);
dim = -0.5 + sqrt(0.25 + 2*len);
Mat = zeros(dim,dim);
ind=1;

for i=1:dim
    for j=i:dim
        Mat(j,i)=V(ind);
        ind=ind+1;
    end