% this algorithm returns the indexes of the entries of a vec that
% correspond to the diagonal elements of original matrix: e.g. if x is the
% col(row) entry of A, it returns the position in vec(A)
%%%%%%%%%%%%%%%%
% [pos]=whereinvec_var(ely,n);
% input: ely=index vector of the searched elements
%        n = number of variables in the original square matrix
% output: pos= index of the vec vector that correspond to the input index       
%        
% example: look for the variables [1] in the vec(cov-matrix)

function [pos]=whereinvec_var(ely,n);
pos=[];
for jj=1:length(ely);
pos(jj,1)=ely(jj)+(n*(ely(jj)-1));
end
return