Home > source > @penlab > vec2Y.m

# vec2Y

## PURPOSE

Map 'vectorized' matrix decision variables back to cell array of matrices Y

## SYNOPSIS

function Y=vec2Y(obj, vec)

## DESCRIPTION

     Map 'vectorized' matrix decision variables back to cell array of matrices Y
     by usage of obj.vec2Ymap, see createY1map() for details
       vec  ... vector of length obj.NYnnz
       Y  ... cell array obj.NY x 1 with filled in 'vec' to the proper nnz places
           Y is returned as symmetric

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- penlab PenLab (Pennon Laboratory for Matlab, previously PennonM)

## SOURCE CODE

    0001 % Map 'vectorized' matrix decision variables back to cell array of matrices Y
    0002 % by usage of obj.vec2Ymap, see createY1map() for details
    0003 %   vec  ... vector of length obj.NYnnz
    0004 %   Y  ... cell array obj.NY x 1 with filled in 'vec' to the proper nnz places
    0005 %       Y is returned as symmetric
    0006 function  Y=vec2Y(obj, vec)
    0007
    0008   % perhaps skip this?
    0009   if (length(vec) ~= obj.NYnnz)
    0010     error('map vec->Y, wrong length of vec');
    0011   end
    0012
    0013   if (obj.NY>0)
    0014     Y=cell(obj.NY,1);
    0015
    0016     for k=1:obj.NY
    0017       % create Y{k} as appropriate
    0018       mapper=obj.vec2Ymap{k};
    0019       if (mapper.dense)
    0020         %Y{k}=zeros(mapper.dim);
    0021         %Y{k}(:)=mapper.xmap(vec);
    0022         Y{k}=reshape(vec(mapper.xmap),mapper.dim, mapper.dim);
    0023       else
    0024         % sparse
    0025         Y{k}=sparse(mapper.irow, mapper.icol, vec(mapper.xmap), mapper.dim, mapper.dim);
    0026         %sparse(i,j,s,m,n)
    0027       end
    0028     end
    0029
    0030   else
    0031     Y=[];
    0032   end
    0033 end