numSubplots - neatly arrange subplots

版本 1.0.0.0 (1.5 KB) 作者: Rob Campbell
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)

Inputs
n - the desired number of subplots.

Outputs
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 (https://www.mathworks.com/matlabcentral/fileexchange/26310-numsubplots-neatly-arrange-subplots), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2009a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Subplots 的更多信息
致谢

启发作品: BestArrayDims

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0