NANCAT

版本 1.0.0.0 (2.3 KB) 作者: Sanjay Manohar
Like CAT, but padding with NaNs. Doesn't complain if input sizes heterogeneous. Faster than CATPAD.
450.0 次下载
更新时间 2013/2/20

查看许可证

I wrote this some years back before I knew CATPAD existed. I'm putting it out here because it's between 2 to 4.5 times faster.

Syntax:

X = NANCAT( DIM, X1, X2, ... )

concatenates along dimension DIM, but doesn't complain if the items are all of different sizes. Pads the smaller matrices with NAN.

Generalises fully to N dimensional arrays.

X = NANCAT( DIM, X..., 'padvalue', P )

Pads with the value P rather than NAN. P must be a scalar.

Also handles cell arrays and char arrays; default padding cell is { [] }, and default char is ' '.

X = NANCAT( DIM, X..., 'alignend')

Aligns the new items at the end of the dimensions being padded - i.e. the padding goes "in front". For example,

NANCAT(1,[1 2 3; 4 5 6], [7 8])
ans =
[ 1 2 3
4 5 6
7 8 nan ]

but
NANCAT(1, [1 2 3; 4 5 6], [7 8], 'alignend')
ans =
[ 1 2 3
4 5 6
nan 7 8 ]

Notes for unusual cases:
* If any concatenands are cells, the output is a cell.
* If any of the concatenands are numeric, they are turned into cell arrays with num2cell.
* If the first operand isn't a cell, but later ones are, we default to padding with { [nan] }, rather than { [] }.
* Unlike CATPAD it does not return a flag matrix. Maybe that's why it's faster.

引用格式

Sanjay Manohar (2024). NANCAT (https://www.mathworks.com/matlabcentral/fileexchange/40416-nancat), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2007a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 NaNs 的更多信息
标签 添加标签

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0