Arrange n elements in an array (for subplots).


Updated 28 Feb 2011

View License

[nr nc] = BestArrayDims(n)
Given n elements, BestArrayDims returns the dimensions of an array in which to store them. The function also accepts user preferences as to whether they require less wasted space or a more square configuration.

I have found this function particularly well-suited for finding subplot dimensions if it is not known in advance the number of plots that will be needed.

Cite As

Zachary Danziger (2023). BestArrayDims (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: numSubplots - neatly arrange subplots

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes