Home > atmlab > arts > arts_y2tensor.m

arts_y2tensor

PURPOSE ^

ARTS_Y2TENSOR Rearrange a measurement vector to a tensor

SYNOPSIS ^

function Y = arts_y2tensor(y,nf,varargin)

DESCRIPTION ^

 ARTS_Y2TENSOR   Rearrange a measurement vector to a tensor

    ARTS returns the data as a single vector, *y*. This function rearrange
    the data into a 4D tensor *Y*. The dimensions of the tensor are:
       [ frequency, polarisation, line-of-sight, measurement block ]

    The number of frequencies, polarisations, line-of-sights and
    measurement blocks must be specified. However, if the size of a
    dimension is set to -1, an automatic selection is made (to match lenthn
    of *y*). Of course, -1 can only be set for a single dimension.

 FORMAT   Y = arts_y2tensor(y,nf[,npol,nlos,nblock])
        
 OUT   Y        The data in *y* as a tensor with size [nf,npol,nlos,nblock].
 IN    y        Measurement vector
       nf       Number of frequencies.
 OPT   npol     Number of polarisations. Default is 1.
       nlos     Number of line-of-sights. Default is 1.
       nblock   Number of measurement blocks. Default is 1.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

arts_y2tensor.m

SOURCE CODE ^

0001 % ARTS_Y2TENSOR   Rearrange a measurement vector to a tensor
0002 %
0003 %    ARTS returns the data as a single vector, *y*. This function rearrange
0004 %    the data into a 4D tensor *Y*. The dimensions of the tensor are:
0005 %       [ frequency, polarisation, line-of-sight, measurement block ]
0006 %
0007 %    The number of frequencies, polarisations, line-of-sights and
0008 %    measurement blocks must be specified. However, if the size of a
0009 %    dimension is set to -1, an automatic selection is made (to match lenthn
0010 %    of *y*). Of course, -1 can only be set for a single dimension.
0011 %
0012 % FORMAT   Y = arts_y2tensor(y,nf[,npol,nlos,nblock])
0013 %
0014 % OUT   Y        The data in *y* as a tensor with size [nf,npol,nlos,nblock].
0015 % IN    y        Measurement vector
0016 %       nf       Number of frequencies.
0017 % OPT   npol     Number of polarisations. Default is 1.
0018 %       nlos     Number of line-of-sights. Default is 1.
0019 %       nblock   Number of measurement blocks. Default is 1.
0020 
0021 % 2011-08-29   Created by Patrick Eriksson.
0022 
0023 function Y = arts_y2tensor(y,nf,varargin)
0024 %
0025 [npol,nlos,nblock] = optargs( varargin, { 1, 1, 1 } );
0026 
0027 
0028 %- Automatic detection of length
0029 %
0030 ny = length(y);
0031 %
0032 if npol < 0
0033   npol = ny / (nf*nlos*nblock);
0034 elseif nlos < 0
0035   nlos = ny / (nf*npol*nblock);
0036 elseif nlos < 0
0037   nblock = ny / (nf*npol*nlos);
0038 end  
0039 
0040 
0041 % Checks:                                                                  %&%
0042 if nf < 1  |  ~iswhole(nf)                                                 %&%
0043   error( 'The argument *nf* must be an integer >= 1.' );                   %&%
0044 end                                                                        %&%
0045 if npol < 1  |  ~iswhole(npol)                                             %&%
0046   error( 'The argument *npol* must be an integer >= 1.' );                 %&%
0047 end                                                                        %&%
0048 if nlos < 1  |  ~iswhole(nlos)                                             %&%
0049   error( 'The argument *nlos* must be an integer >= 1.' );                 %&%
0050 end                                                                        %&%
0051 if nblock < 1  |  ~iswhole(nblock)                                         %&%
0052   error( 'The argument *nblock* must be an integer >= 1.' );               %&%
0053 end                                                                        %&%
0054 if nf*npol*nlos*nblock ~= ny                                               %&%
0055   error( 'The product nf*npol*nlos*nblock doesnot match length of *y*.' ); %&%
0056 end                                                                        %&%
0057 
0058 
0059 % Rearrange data
0060 %
0061 Y = zeros( nf, npol, nlos, nblock );
0062 %
0063 for i = 1 : npol
0064   Y(:,i,:,:) = reshape( y(i:npol:end), [ nf, 1, nlos, nblock ] );
0065 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005