recarray(inarray,n)

Creates a pseudo-recursive version of simple 1D arrays

You are now following this Submission

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.

Cite As

ja (2026). recarray(inarray,n) (https://www.mathworks.com/matlabcentral/fileexchange/66390-recarray-inarray-n), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0