This repository was archived by the owner on Dec 10, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ function [h ] = mapplots(n , plotFun , varargin )
2+ % MAPPLOTS Create a figure with multiple plots, using anonymous functions.
3+ %
4+ % SYNTAX:
5+ % mapsubplots(n, plotFun)
6+ % h = mapsubplots(...)
7+ %
8+ % INPUT:
9+ % n = number of plots to create.
10+ % plotFun = function handle to a function of the following prototype:
11+ % h = plotFun(idx)
12+ % with:
13+ % idx = index of the subplot.
14+ % h = the handle of the plot created.
15+ % The function should call plotting functions to create the actual plots,
16+ % and return the created plot handle.
17+ %
18+ % OUTPUT:
19+ % h = cell array with plot handles of the plots created.
20+ %
21+ % EXAMPLES:
22+ % mapplots(4, @(i) plot(i.*rand(100,1), '-'));
23+ %
24+ % SEE ALSO:
25+ % sprintf
26+
27+ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28+ %% Parse & validate input
29+
30+ if ~isa(plotFun , ' function_handle' )
31+ error(' Invalid argument "plotFun": function handle expected.' );
32+ end
33+
34+ defArgs = struct(...
35+ );
36+ args = pargs(varargin , defArgs );
37+
38+
39+ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40+ %% Make plots
41+
42+ figure ;
43+
44+ h = cell(n ,1 );
45+
46+ for iPlot = 1 : n
47+ h{iPlot } = plotFun(iPlot );
48+ if iPlot == 1
49+ hold(' on' );
50+ end
51+ end
52+
53+ end
54+
You can’t perform that action at this time.
0 commit comments