arraypat

This function searches for a pattern in an array

You are now following this Submission

This function searches for an n-dimentional pattern in a k-dimentional array.
Its output is the linear indices of the beginnings of matches. Matches can overlap.
There are 2 debug blocks: the first is for generation of a random array & pattern, and the second is for output check using subscripts and ranges.
I tested the function on random 0-9-dimentional arrays and patterns, and on arrays which were repmats of patterns (to compare performance when there are a lot of matches with performance when there aren't).
  • Note that NaN's are not equal to each other, and will not match.
Much thanks goes to whoever wrote ind2sub, as I took some ideas from it for the n-dimentional loop.

Cite As

Anan Yablonko (2026). arraypat (https://www.mathworks.com/matlabcentral/fileexchange/110855-arraypat), 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.1

Fixed an obvious bug

1.0.0