Skip to content

Instantly share code, notes, and snippets.

@kevin-d-omara
Last active December 12, 2017 04:53
Show Gist options
  • Save kevin-d-omara/0b41a5d2895e0f0535ff39e700d3f7cf to your computer and use it in GitHub Desktop.
Save kevin-d-omara/0b41a5d2895e0f0535ff39e700d3f7cf to your computer and use it in GitHub Desktop.
Create subplots dynamically, great for prototyping.
function makePlot = MakeAutoSubplot(numRows, numCols)
% Creates a new subplot each time 'makePlot()' is called. Subplots are
% arranged in a numRows-by-numCols grid. See Matlab documentation on
% subplot for details.
%
% Uses a closure of 'numRows' & 'numCols' to take care of bookeeping.
%
% Return:
% makePlot - function pointer; calling it creates the next subplot
%
% Parameters:
% numRows - number of subplot rows
% numCols - number of subplot column
i = 1;
function g()
subplot(numRows, numCols, i);
i = i + 1;
end
makePlot = @g;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment