from
Dimension Expansion Toolbox
by Ingo Löhken
Expands functions to usage of N dimensional inputs.
|
| opdim(SIZ,DIM);
|
function DIM = opdim(SIZ,DIM);
% OPDIM Operating dimension.
% DIM = OPDIM(SIZ) or OPDIM(SIZ,[]) is the first non singleton dim-
% ension in the N-D array of size SIZ.
%
% DIM = OPDIM(SIZ,DIM) is the dimension DIM in an N-D array of size
% SIZ, if the dimension is valid. If the dimension is unvalid or is
% set to the default dimension DIM = [] the first non singleton dim-
% ension along the N-D array of size SIZ is returned.
%
% See also NDOP.
%
% @author Ingo Lhken, ingo.loehken@gmx.de
% @rev 26/10/2005
% @toolbox DIMEXP, ver 0.1
try;
error(nargchk(1,2,nargin));
error(nargoutchk(0,1,nargout));
if ndims(SIZ) > 2 || ~isnumeric(SIZ) || ~any(size(SIZ) <= 1);
error('~isvector(SIZ)');
elseif any(floor(SIZ) ~= SIZ);
error('~isnat(SIZ)');
end;
% Translate Operating Dimension
if nargin < 2 || isempty(DIM);
S = find(SIZ > 1);
if isempty(S);
DIM = 1;
else;
DIM = S(1);
end;
else;
try;
if ndims(DIM) > 2 || any(size(DIM) ~= 1) || ~isnumeric(DIM);
error('~isscalar(DIM)');
elseif DIM <= 0;
error('DIM <= 0');
elseif DIM > length(SIZ);
error('DIM > length(SIZ)');
end;
catch;
evalin('caller','warning(''Operating dimension DIM is out dimensions and set to first operating one.'')');
DIM = opdim(SIZ,[]);
end;
end;
catch;
error([mfilename,': ',lasterr]);
end;
|
|
Contact us at files@mathworks.com