4.5

4.5 | 2 ratings Rate this file 157 downloads (last 30 days) File Size: 3.04 KB File ID: #22909

PADCAT

by Jos

 

06 Feb 2009

Code covered by BSD License  

concatenate vectors with different lengths by padding with NaN (v1.0, feb 2009)

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

Download Now | Watch this File

File Information
Description

PADCAT - concatenate vectors with different lengths by padding with NaN
 
    M = PADCAT(V1, V2, V3, ..., VN) concatenates the vectors V1 through VN
    into one large matrix. All vectors should have the same orientation,
    that is, they are all row or column vectors. The vectors do not need to
    have the same lengths, and shorter vectors are padded with NaNs.
    The size of M is determined by the length of the longest vector. For
    row vectors, M will be a N-by-MaxL matrix and for column vectors, M
    will be a MaxL-by-N matrix, where MaxL is the length of the longest
    vector.
 
    Examples:
       a = 1:5 ; b = 1:3 ; c = [] ; d = 1:4 ;
       padcat(a,b,c,d) % row vectors
          % -> 1 2 3 4 5
          % 1 2 3 NaN NaN
          % NaN NaN NaN NaN NaN
          % 1 2 3 4 NaN
       CC = {d.' a.' c.' b.' d.'} ;
       padcat(CC{:}) % column vectors
          % 1 1 NaN 1 1
          % 2 2 NaN 2 2
          % 3 3 NaN 3 3
          % 4 4 NaN NaN 4
          % NaN 5 NaN NaN NaN
 
 
    [M, TF] = PADCAT(..) will also return a logical matrix TF with the same
    size as R having true values for those positions that originate from an
    input vector. This may be useful if any of the vectors contain NaNs.
 
    Example:
        a = 1:3 ; b = [] ; c = [1 NaN] ;
        [M,tf] = padcat(a,b,c)
        % find the original NaN
        [Vev,Pos] = find(tf & isnan(M))
        % -> Vec = 3 , Pos = 2
 
    Scalars will be concatenated into a single column vector.
 
    See also cat, reshape, strvcat, char, horzcat, vertcat, isempty
             nones, group2cell (Matlab File Exchange)

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
padadd

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
04 Jun 2009 Kent Conover

Works as advertised - many thanks!

01 Jul 2009 Laurence Johns  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
matrix Jos 06 Feb 2009 12:20:06
matrices Jos 06 Feb 2009 12:20:06
matrix manipulation Jos 06 Feb 2009 12:20:06
cat Jos 06 Feb 2009 12:20:06
concatenate Jos 06 Feb 2009 12:20:06
add Jos 06 Feb 2009 12:20:06
merge Jos 06 Feb 2009 12:20:06
fill Jos 06 Feb 2009 12:20:06
combine Jos 06 Feb 2009 12:20:06
lengths Jos 06 Feb 2009 12:20:06
different Jos 06 Feb 2009 12:20:06
nans Jos 06 Feb 2009 12:20:06
vectors Jos 06 Feb 2009 12:20:06
potw Shari Freedman 04 Sep 2009 14:27:03
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com