Code covered by the BSD License

5.0
5.0 | 8 ratings Rate this file 20 Downloads (last 30 days) File Size: 4.38 KB File ID: #33453 Version: 1.2

### Jonathan Sullivan (view profile)

26 Oct 2011 (Updated )

Concatenation of arbitrarily sized data along any dimension.

File Information
Description

M = CATPAD(dim,A1, A2, A3, ..., AN) concatenates along the dimension
DIM the arrays A1 through AN into one large matrix. The vectors do
not need to have the same size, nor number of dimensions. The size
of the output M is determined by the dimmention of concatenation,
and the size of the inputs. Any inputs that are not the correct
size will be padded with NaNs if the inputs are numeric. If they
are strings, they will be padded with a space " ".

specified by PADVAL. The default is NaN for numeric inputs, and a
space " " for string inputs.

[M TF] = CATPAD(...) outputs ana array of logicals TF having true
values when the values in that position of M were from the original

Examples:
a = 1:4; b = 1:5; c = []; d = 1:3; dim = 1;
M =
1 2 3 4 NaN
1 2 3 4 5
1 2 3 NaN NaN
% Note: The input "c" was empty, and therefore doesn't require it's
% own row.

a = rand(3); b = magic(5); c = rand([4 5 4]); dim = 3;
size(M)
5 5 6

str1 = 'What do you think of this function?';
str2 = 'I like it!';
dim = 1;
M =
What do you think of this function?
I like it!

Example: Find original NaNs
a = 1:3; b = [2:5 NaN]; c = [1 NaN]; dim = 1;
% find the original NaN
[row,col] = find(tf & isnan(M))
% -> row = [3 2] , col = [2 5]

a = 1:3; b = 1; c = 1:4; dim = 1; padval = inf;
M =
1 2 3 Inf
1 Inf Inf Inf
1 2 3 4

By Jonathan Sullian - October 2011

Many thanks to Michael VĂ¶lker for his function sub2allind which has made
this function possible. Also, I would like to aknowledge Jos (10584)
whose submission padcat has inspired this one.

Acknowledgements

Padcat(Varargin) and Sub2allind inspired this file.

MATLAB release MATLAB 7.12 (R2011a)
07 Jun 2016 bugguts99

### bugguts99 (view profile)

18 Mar 2015 Santhan Salai

### Santhan Salai (view profile)

03 Oct 2014 Christian

### Christian (view profile)

This is really great work. Thanks for your kind contribution.

21 Oct 2013 Dan K

22 Aug 2013 Ivo

### Ivo (view profile)

24 Jan 2013 Heather

### Heather (view profile)

I second Harold's sentiment.

23 Jan 2013 Harold Bell

### Harold Bell (view profile)

I just want to say that this function AWESOME.

26 Oct 2011 Mike Sheppard