CATPAD

버전 1.2.0.0 (4.38 KB) 작성자: Jonathan Sullivan
Concatenation of arbitrarily sized data along any dimension.
다운로드 수: 1.6K
업데이트 날짜: 2011/10/26

라이선스 보기

CATPAD - concatenate matrices with different sizes by padding with NaN.

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 " ".

[M TF] = CATPAD(...,'padval',padval) pads the input data with the value
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
data (i.e. not padded).

Examples:
a = 1:4; b = 1:5; c = []; d = 1:3; dim = 1;
M = catpad(dim,a,b,c,d)
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;
M = catpad(dim,a,b,c);
size(M)
5 5 6

str1 = 'What do you think of this function?';
str2 = 'I like it!';
dim = 1;
M = catpad(1,str1,str2)
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;
[M,tf] = catpad(dim,a,b,c)
% 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 = catpad(dim,a,b,c,'padval',padval)
M =
1 2 3 Inf
1 Inf Inf Inf
1 2 3 4

See also CAT, RESHAPE, STRVCAT, CHAR, HORZCAT, VERTCAT, ISEMPTY

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.

인용 양식

Jonathan Sullivan (2024). CATPAD (https://www.mathworks.com/matlabcentral/fileexchange/33453-catpad), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2011a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
도움

도움 받은 파일: PADCAT, sub2allind

도움 준 파일: CATX

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.2.0.0

Expanded functionality to handle cell arrays.

1.1.0.0

Modified H1 line to more accurately reflect the functionality of the function.

1.0.0.0