repToSize

版本 1.0.0.0 (2.3 KB) 作者: Jason Kaeding
Replicate and tile an array so that it meets a specified final size.
293.0 次下载
更新时间 2010/10/21

查看许可证

repToSize is an adaptation of repmat which requires only the final array size as the input. This removes the need to calculate the number of repetitions as well as handling for cases where a a fractional number of repetitions is required.

If the final
size is not a multiple of the original array's size, the appropriate partition
of the array will be used to fill the remaining values.

In pictoral form for the 2D case:

If A = [m x n array], then
B = repToSize(A,x,y) produces
| A A .. A A2 |
| A A .. A A2 |
| .. .. .. .. .. |
| A A .. A A2 |
| A1 A1 .. A1 A3 |
where x >= m, y >= n, and
A1 = A(1:rem(x,m),:)
A2 = A(:,1:rem(y,n))
A3 = A(1:rem(x,m),1:rem(y,n))

If, for example, x < m and y < n, then B will simply be equal to A3.


Example:
A = reshape([1:3*4*5],[3 4 5]); % a 3x4x5 array of values from 1 to 60
B = repToSize(A,[13 19 3]) % create a 13 x 19 x 3 array, replicating values
B = repToSize(A,13,19,3) % alternate syntax

In this example, B(:,1,:) will contain repeated copies of [1;2;3] with a 1
as the final entry (13 is not a multiple of 3). B(1,:,:) will
contain repeated copies of [1,4,7,10], ending in 7 as the last entry in the
row (19 is not a multiple of 4).

引用格式

Jason Kaeding (2024). repToSize (https://www.mathworks.com/matlabcentral/fileexchange/29106-reptosize), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2010b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Numeric Types 的更多信息

Community Treasure Hunt

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

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