2%> Create axes in the specified input tiled position and
return its handle.<br>
4%> \param[in] varargin : Any attributes of the axes,
which can be one of the following positional arguments:<br>
6%> <li> ``rows `` : The input scalar MATLAB whole number,
7%> representing the number of rows of subplots in the figure.<br>
8%> <li> ``cols `` : The input scalar MATLAB whole number,
9%> representing the number of columns of subplots in the figure.<br>
10%> <li> ``cellx`` : The input scalar MATLAB whole number,
11%> representing the row at
which the
new axes must be placed in the figure.<br>
12%> <li> ``celly`` : The input scalar MATLAB whole number,
13%> representing the column at
which the
new axes must be placed in the figure.<br>
14%> <li> ``spanx`` : The input scalar MATLAB whole number in the range ``[0, 1]``,
15%> representing the X-span of the current axes in the figure.<br>
16%> <li> ``spany`` : The input scalar MATLAB whole number in the range ``[0, 1]``,
17%> representing the Y-span of the current axes in the figure.<br>
19%> or specified as pairs of scalar ``
char``,
20%> followed by the specifications value in the range ``[0, 1]``.<br>
21%> The following attributes are acceptable:<br>
23%> <li> ``
'Spacing'`` , also ``
's'``
24%> <li> ``
'SpacingHoriz'`` , also ``
'sh'``
25%> <li> ``
'SpacingVert'`` , also ``
'sv'``
26%> <li> ``
'Padding'`` , also ``
'p'``
27%> <li> ``
'PaddingRight'`` , also ``
'pr'``
28%> <li> ``
'PaddingLeft'`` , also ``
'pl'``
29%> <li> ``
'PaddingTop'`` , also ``
'pt'``
30%> <li> ``
'PaddingBottom'`` , also ``
'pb'``
31%> <li> ``
'Margin'`` , also ``
'm'``
32%> <li> ``
'MarginRight'`` , also ``
'mr'``
33%> <li> ``
'MarginLeft'`` , also ``
'ml'``
34%> <li> ``
'MarginTop'`` , also ``
'mt'``
35%> <li> ``
'MarginBottom'`` , also ``
'mb'``
36%> <li> ``
'Holdaxis'`` , also ``
'h'`` : If ``
true``, any axes below the current will not be deleted.
38%> (**optional**. If missing, a fedault value will be used.)
43%> h =
getAxes(rows, cols, cellno, varargin)
44%> h =
getAxes(rows, cols, cellx, celly, varargin)
45%> h =
getAxes(rows, cols, cellx, celly, spanx, spany, varargin)
50%> \include{lineno} example/vis/axes/
getAxes/main.m
56%> This code builds upon the works of 2001-2014 / Aslak Grinsted.<br>
59%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
60%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
64 args = get(f,
'UserData');
66 userDataArgsOK = isfield(args,
'SpacingHorizontal') & isfield(args,
'Holdaxis') & isfield(args,
'rows') & isfield(args,
'cols');
68 OKToStoreArgs = isempty(args) | userDataArgsOK;
69 if isempty(args) && (~userDataArgsOK)
70 args =
struct(
'Holdaxis',0, ...
71 'SpacingVertical',0.05,
'SpacingHorizontal',0.05, ...
72 'PaddingLeft',0,
'PaddingRight',0,
'PaddingTop',0,
'PaddingBottom',0, ...
73 'MarginLeft',.1,
'MarginRight',.1,
'MarginTop',.1,
'MarginBottom',.1, ...
76 args = parseArgs(varargin,args,{
'Holdaxis'},{
'Spacing' {
'sh',
'sv'};
'Padding' {
'pl',
'pr',
'pt',
'pb'};
'Margin' {
'ml',
'mr',
'mt',
'mb'}});
77 if (length(args.NumericArguments)>2)
78 args.rows=args.NumericArguments{1};
79 args.cols=args.NumericArguments{2};
80 %remove these 2 numerical arguments
81 args.NumericArguments={args.NumericArguments{3:end}};
84 set(f,
'UserData',args);
86 switch length(args.NumericArguments)
88 return % no arguments but rows/cols....
90 if numel(args.NumericArguments{1}) > 1 % restore subplot(m,n,[x y]) behaviour
91 [x1 y1] = ind2sub([args.cols args.rows],args.NumericArguments{1}(1)); % subplot and ind2sub count differently (column instead of row first) -->
switch cols/rows
92 [x2 y2] = ind2sub([args.cols args.rows],args.NumericArguments{1}(end));
94 x1=mod((args.NumericArguments{1}-1),args.cols)+1; x2=x1;
95 y1=floor((args.NumericArguments{1}-1)/args.cols)+1; y2=y1;
97 % x1=mod((args.NumericArguments{1}-1),args.cols)+1; x2=x1;
98 % y1=floor((args.NumericArguments{1}-1)/args.cols)+1; y2=y1;
100 x1=args.NumericArguments{1};x2=x1;
101 y1=args.NumericArguments{2};y2=y1;
103 x1=args.NumericArguments{1};x2=x1+args.NumericArguments{3}-1;
104 y1=args.NumericArguments{2};y2=y1+args.NumericArguments{4}-1;
106 error(
'getAxes argument error')
109 cellwidth=((1-args.MarginLeft-args.MarginRight)-(args.cols-1)*args.SpacingHorizontal)/args.cols;
110 cellheight=((1-args.MarginTop-args.MarginBottom)-(args.rows-1)*args.SpacingVertical)/args.rows;
111 xpos1=args.MarginLeft+args.PaddingLeft+cellwidth*(x1-1)+args.SpacingHorizontal*(x1-1);
112 xpos2=args.MarginLeft-args.PaddingRight+cellwidth*x2+args.SpacingHorizontal*(x2-1);
113 ypos1=args.MarginTop+args.PaddingTop+cellheight*(y1-1)+args.SpacingVertical*(y1-1);
114 ypos2=args.MarginTop-args.PaddingBottom+cellheight*y2+args.SpacingVertical*(y2-1);
116 h=axes('position',[xpos1 1-ypos2 xpos2-xpos1 ypos2-ypos1]);
118 h=subplot('position',[xpos1 1-ypos2 xpos2-xpos1 ypos2-ypos1]);
121 %h=axes('position',[x1 1-y2 x2-x1 y2-y1]);
122 set(h,'units',get(gcf,'defaultaxesunits'));
124 if (nargout==0), clear h; end;
129function argStruct = parseArgs(args, argStruct, varargin)
130 % Helper function for parsing varargin.
132 % argStruct=parseArgs(varargin,argStruct[,FlagtypeParams[,Aliases]])
134 % * argStruct is the structure full of named arguments with default values.
135 % * Flagtype params is params that don't require a value. (the value will be set to 1 if it is present)
136 % * Aliases can be used to
map one argument-
name to several argstruct fields
140 % function parseargtest(varargin)
142 % %define the acceptable named arguments and assign default values
143 % args=struct('Holdaxis',0, ...
144 % 'SpacingVertical',0.05,'SpacingHorizontal',0.05, ...
145 % 'PaddingLeft',0,'PaddingRight',0,'PaddingTop',0,'PaddingBottom',0, ...
146 % 'MarginLeft',.1,'MarginRight',.1,'MarginTop',.1,'MarginBottom',.1, ...
147 % 'rows',[],'cols',[]);
149 % %The capital letters define abrreviations.
150 % % Eg. parseargtest('spacingvertical',0) is equivalent to parseargtest('sv',0)
152 % args=parseArgs(varargin,args, ... % fill the arg-struct with values entered by the user
153 % {
'Holdaxis'}, ... %
this argument has no value (flag-type)
154 % {
'Spacing' {
'sh',
'sv'};
'Padding' {
'pl',
'pr',
'pt',
'pb'};
'Margin' {
'ml',
'mr',
'mt',
'mb'}});
161 % Aslak Grinsted 2004
162 % -------------------------------------------------------------------------
163 % Copyright (C) 2002-2004, Aslak Grinsted
164 % This software may be used, copied, or redistributed as
long as it is not
165 % sold and
this copyright notice is reproduced on each
copy made. This
166 % routine is provided as is without any express or implied warranties
169 if isempty(matlabver)
170 matlabver=ver(
'MATLAB');
171 matlabver=str2double(matlabver.Version);
175 if (length(varargin)>0)
176 FlagTypeParams=lower(strvcat(varargin{1})); %#ok
177 if length(varargin)>1
182 %---------------Get
"numeric" arguments
184 while (NumArgCount<=size(args,2))&&(~ischar(args{NumArgCount}))
185 NumArgCount=NumArgCount+1;
187 NumArgCount=NumArgCount-1;
189 argStruct.NumericArguments={args{1:NumArgCount}};
191 argStruct.NumericArguments={};
193 %--------------Make an accepted fieldname matrix (
case insensitive)
194 Fnames=fieldnames(argStruct);
195 for i=1:length(Fnames)
196 name=lower(Fnames{i,1});
197 Fnames{i,2}=
name; %col2=lower
198 Fnames{i,3}=[
name(Fnames{i,1}~=
name)
' ']; %col3=abreviation letters (those that are uppercase in the argStruct) e.g. SpacingHoriz->sh
199 %the space prevents strvcat from removing empty lines
200 Fnames{i,4}=isempty(strmatch(Fnames{i,2},FlagTypeParams)); %Does
this parameter have a value?
202 FnamesFull=strvcat(Fnames{:,2}); %#ok
203 FnamesAbbr=strvcat(Fnames{:,3}); %#ok
205 for i=1:length(Aliases)
206 name=lower(Aliases{i,1});
207 FieldIdx=strmatch(
name,FnamesAbbr,
'exact'); %
try abbreviations (must be exact)
209 FieldIdx=strmatch(
name,FnamesFull); %&??????? exact or not?
211 Aliases{i,2}=FieldIdx;
212 Aliases{i,3}=[
name(Aliases{i,1}~=
name)
' ']; %the space prevents strvcat from removing empty lines
213 Aliases{i,1}=
name; %dont need the
name in uppercase anymore
for aliases
215 %Append aliases to the end of FnamesFull and FnamesAbbr
216 FnamesFull=strvcat(FnamesFull,strvcat(Aliases{:,1})); %#ok
217 FnamesAbbr=strvcat(FnamesAbbr,strvcat(Aliases{:,3})); %#ok
219 %--------------get parameters--------------------
221 while (l<=length(args))
224 paramHasValue=1; % assume that the parameter has is of type
'param',value
226 FieldIdx=strmatch(a,FnamesAbbr,
'exact'); %
try abbreviations (must be exact)
228 FieldIdx=strmatch(a,FnamesFull);
230 if (length(FieldIdx)>1) %shortest fieldname should
win
231 [mx,mxi]=max(sum(FnamesFull(FieldIdx,:)==
' ',2));%#ok
232 FieldIdx=FieldIdx(mxi);
234 if FieldIdx>length(Fnames) %then it
's an alias type.
235 FieldIdx=Aliases{FieldIdx-length(Fnames),2};
239 error(['Unknown named parameter:
' a])
241 for curField=FieldIdx' %
if it is an alias it could be more than one.
242 if (Fnames{curField,4})
243 if (l+1>length(args))
244 error([
'Expected a value for parameter: ' Fnames{curField,1}])
248 if (l<length(args)) %there might be a explicitly specified value
for the flag
254 error([
'Invalid value for flag-parameter: ' Fnames{curField,1}])
266 argStruct.(Fnames{curField,1})=val; %
try the line below
if you get an error here
268 argStruct=setfield(argStruct,Fnames{curField,1},val); %#ok <-works in old matlab versions
271 l=l+1+paramHasValue; %
if a wildcard matches more than one
273 error([
'Expected a named parameter: ' num2str(a)])
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared library directories.
function copy(in from, in to, in field, in exclude)
Copy the contents of the struct/object from to the struct/object to recursively and without destroyin...
function getAxes(in varargin)
Create axes in the specified input tiled position and return its handle.
function isnumeric(in str)
Return a scalar MATLAB logical that is true if and only if the input string can be converted to a sca...
function map()
Return a scalar MATLAB logical that is true if and only if the current installation of MATLAB contain...
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...
function win()
Return true if the current OS is Windows.