PADCAT

버전 1.4.0.0 (3.21 KB) 작성자: Jos (10584)
concatenate vectors with different lengths by padding with NaN
다운로드 수: 14.9K
업데이트 날짜: 2018/12/5

라이선스 보기

편집자 메모: This file was selected as MATLAB Central Pick of the Week

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
This second output can also be used to change the padding value into something else than NaN.
[M, tf] = padcat(1:3,1,1:4)
M(~tf) = 99 % change the padding value into 99

Scalars will be concatenated into a single column vector.

See also cat, reshape, strvcat, char, horzcat, vertcat, isempty
nones, group2cell (Matlab File Exchange)

인용 양식

Jos (10584) (2024). PADCAT (https://www.mathworks.com/matlabcentral/fileexchange/22909-padcat), MATLAB Central File Exchange. 검색됨 .

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

받음: padadd

줌: CATALIGN, CATX, CATPAD

Community Treasure Hunt

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

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

removed some irrelevant code warnings

1.3.0.0

updated description
updated contact info, and update argument checking

1.1.0.0

added help on how to change the padding value using the secondary output

1.0.0.0