Home > utilities > packmat.m

# packmat

## PURPOSE

PACKMAT assumes a symmetric matrix on input and returns its 'L' packed

## SYNOPSIS

function [Ap] = packmat(A)

## DESCRIPTION

     PACKMAT assumes a symmetric matrix on input and returns its 'L' packed
     representation i.e., a dense vector of length n*(n+1)/2 set up
     by columns of the lower triangle of A

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 function [Ap] = packmat(A)
    0002 % PACKMAT assumes a symmetric matrix on input and returns its 'L' packed
    0003 % representation i.e., a dense vector of length n*(n+1)/2 set up
    0004 % by columns of the lower triangle of A
    0005
    0006 % This file is a part of PENLAB package distributed under GPLv3 license
    0007 % Copyright (c) 2013 by  J. Fiala, M. Kocvara, M. Stingl
    0008 % Last Modified: 27 Nov 2013
    0009
    0010   [n m] = size(A);
    0011   if (n~=m)
    0012     error('Input matrix needs to be square.')
    0013   end
    0014
    0015   Ap = zeros(n*(n+1)/2,1);
    0016   offset=1;
    0017   for j=1:n
    0018     len=n-j;
    0019     Ap(offset:offset+len)=A(j:n,j);
    0020     offset=offset+len+1;
    0021   end
    0022