📄 index.m
字号:
function res = index(varargin)% DESCRIPTION res = index(r,c,...,dims)% A flat index into a matrix.% The argument list contains index into each dimension of the matrix% (r,c,...) followed by the size of the matrix (dims).% Each dimension of the arguments must either have the same size % or be a singleton. % The last argument (dims) must at least have the length of the % agument list minus two.% If any of the arguments are empty the result is an empty matrix.% TRY % index(1,2,[2 2]) => 3 % index(1,2,3,[2 2 4]) => 11% index(1,2,2) will give the result 3.% index((1:2)',1:2,[2 2])% by Magnus Almgren 970401% Make all but the last input variable into the same size.if min(ndimsm(varargin{1:end-1}))>-1; % no empty indices v = adjsiz(varargin{1:end-1}); % cumprod(dims) cisiz = cumprod(varargin{end}(1:nargin-2)); res = v{1}; for i = 2:nargin-1 res = res + cisiz(i-1).*(v{i}-1); endelse res = [];end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -