0001 function y = ExtendArray(x,s,fill)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 if nargin < 2,
0023 error('Incorrect number of parameters (type ''help <a href="matlab:help ExtendArray">ExtendArray</a>'' for details).');
0024 end
0025 currentSize = size(x);
0026 if length(currentSize) ~= length(s),
0027 error('Array and size do not have the same number of dimensions (type ''help <a href="matlab:help ExtendArray">ExtendArray</a>'' for details).');
0028 end
0029
0030
0031 if nargin < 3,
0032 y = nan(s);
0033 else
0034 if ~isscalar(fill),
0035 error('Incorrect fill value (type ''help <a href="matlab:help ExtendArray">ExtendArray</a>'' for details).');
0036 end
0037 switch(fill),
0038 case 0,
0039 y = zeros(s);
0040 case 1,
0041 y = ones(s);
0042 case inf,
0043 y = inf(s);
0044 otherwise,
0045 y = fill*ones(s);
0046 end
0047 end
0048
0049
0050 indices = arrayfun(@(x) 1:x,currentSize,'uniformoutput',0);
0051 y(indices{:}) = x;