This is a cross between the built-in 'repmat' and 'perm' functions, though neither are used here. If you input a simple 1D array and the number of 'repetitions' you want, this function repeats the array for each element of the array, for each element, for each element, and so on, depending on how many repetitions you are asking for.
For example, you may have an array [a b c d] and you want 3 recursive repetitions. This function (recarray([a b c d],3) would yield the result:
|a b c d a b c d a b c d a b c d a b c d a b c d a b c d a b c d a b c d a b c d a b c d a b c d a b c d a b c d a b c d a b c d|
|a a a a b b b b c c c c d d d d a a a a b b b b c c c c d d d d a a a a b b b b c c c c d d d d a a a a b b b b c c c c d d d d|
|a a a a a a a a a a a a a a a a b b b b b b b b b b b b b b b b c c c c c c c c c c c c c c c c d d d d d d d d d d d d d d d d|
I use this everywhere I use matlab, mostly for indexing, and got a little tired of trying to recreate it every time I move to a new desk. So, I'm uploading it here. Hopefully other people will find it useful.
引用格式
ja (2024). recarray(inarray,n) (https://www.mathworks.com/matlabcentral/fileexchange/66390-recarray-inarray-n), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux类别
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0.0 |