ndindex.m

来自「JLAB is a set of Matlab functions I have」· M 代码 · 共 33 行

M
33
字号
function[y]=ndindex(index,x,dim)%NDINDEX  Indexes a multidimensional array along a specified dimension.%%   Y=NDINDEX(INDEX,X,DIM) indexes the multidimensional array X%   along dimension DIM.  This is equivalent to%		%		    1 2       DIM     DIMS(X)%		    | |        |         |%		Y=X(:,:, ... INDEX, ..., :);		%%   where the location of INDEX is specified by DIM.%%   See also SQUEEZE, DIMS, PERMUTE, SHIFTDIM.%   _________________________________________________________________%   This is part of JLAB --- type 'help jlab' for more information%   (C) 2001, 2004 J.M. Lilly --- type 'help jlab_license' for details          %You would think Matlab would provide a simpler way to do this.str=['y=x('];ndx=length(find(size(x)>1));for i=1:ndx    if i~=dim        str=[str ':,'];    else	str=[str 'index,'];    endendstr=[str(1:end-1) ');'];eval(str);	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?