numSubplots - neatly arrange subplots

Calculate how many rows and columns of sub-plots are needed to neatly display n subplots.
ダウンロード: 1.8K
更新 2010/1/7


Sometimes a graphing function will not know in advance how many sub-plots are to be created. In this case hard-coding the number of rows and columns for the subplot command may not be possible. This function produces reasonable values for the row and column inputs to subplot given the number of desired sub-plots.

function [p,n]=numSubplots(n)

n - the desired number of subplots.

p - a vector length 2 defining the number of rows and number of columns required to show n plots.
[ n - the current number of subplots. This output is used only by this function for a recursive call.]

Example: neatly lay out 13 sub-plots
>> p=numSubplots(13)
p =
3 5
for i=1:13; subplot(p(1),p(2),i), pcolor(rand(10)), end


Rob Campbell (2024). numSubplots - neatly arrange subplots (, MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2009a
Windows macOS Linux
Help Center および MATLAB AnswersSubplots についてさらに検索
タグ タグを追加

ヒントを与えたファイル: BestArrayDims

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート