📄 getm3.m
字号:
function Matrix = getm3(multiMatrix, row, col, ix1, ix2, ix3, ix4, ix5, ix6)% RECVAR, A package for new data types in Matlab 4. % (c) FOA 1997. See the file rvright.m for copyright notice.%% function Matrix = getm3(multiMatrix, row, col, ix1, ix2, ix3, ix4, ix5, ix6)%% Gets a two dimensional matrix from a part of a multidimensional matrix % (multimatrix). The index/subscript (ix1, x2, ...,or ix6) that will form % different rows in the output matrix is specified with the input parameter % "row". %% Matrix A normal 2D Matlab matrix.% multiMatrix MultimatrixT% row% col% ix1, ix2, ix3, ix4, ix5, ix6: Index/subscript (integer row vectors or ':').%% Currently the input parameter "col" is not used. If "row" index is no% vector but there are two other vectors there should be an error message% but there is none. This may be a source to hard-to-find errors.%% If the first index/subscript that is a vector is not the same as specified % with "row" then transpose the output from "getm". If no index is a vector % no transposition is done.%% The indexnumber/subscriptnumber ':' can be used to denote all elements% in a dimension.%% Start : 960930 Svante Bj鰎klund (svabj).% Latest change: $Date: 2000/10/13 19:53:33 $ $Author: svabj $.% $Revision: 1.1 $% *****************************************************************************maxNoIndex = 6;% ****************** Add missing input parameters ******************if (nargin < 9) ix6 = 1;endif (nargin < 8) ix5 = 1;endif (nargin < 7) ix4 = 1;endif (nargin < 6) ix3 = 1;endif (nargin < 5) ix2 = 1;end%if (nargin < 4)% ix1 = 1;%end % ****************** ****************** sizeMM = getr(multiMatrix,'size');MM = getr(multiMatrix, 'matrix');sizeMM = [sizeMM ones(1,maxNoIndex-size(sizeMM,2))];if (isstr(ix1) & (ix1 == ':')) ix1 = 1:sizeMM(1,1);endif (isstr(ix2) & (ix2 == ':')) ix2 = 1:sizeMM(1,2);endif (isstr(ix3) & (ix3 == ':')) ix3 = 1:sizeMM(1,3);endif (isstr(ix4) & (ix4 == ':')) ix4 = 1:sizeMM(1,4);endif (isstr(ix5) & (ix5 == ':')) ix5 = 1:sizeMM(1,5);endif (isstr(ix6) & (ix6 == ':')) ix6 = 1:sizeMM(1,6);endminIndex = [min(ix1),min(ix2),min(ix3),min(ix4),min(ix5),min(ix6)];if (any(minIndex < 1)) error('Some index is to low.')end% check so that no index is larger than the corresponing element in 'sizeMM'.maxIndex = [max(ix1),max(ix2),max(ix3),max(ix4),max(ix5),max(ix6)];if (any(maxIndex > sizeMM)) error('Some index is to high.')end[noIndex1, noIndex2] = matvar('getnoix',sizeMM, ix1, ix2, ix3, ix4, ix5, ix6);index = matvar('expandix',sizeMM, ix1, ix2, ix3, ix4, ix5, ix6);Matrix = reshape(MM(index,1), noIndex1, noIndex2);% ********************* Transpose if necessary for getm3 *********************indexLengths = [length(ix1), length(ix2), length(ix3), length(ix4), ... length(ix5), length(ix6)];noOfIx = 6;%for n = 1:noOfIxn = 1;finished = 0;while ((n <= noOfIx) & ~finished) %fprintf('n=%d, %d & %d \n',n,(indexLengths(n) > 1),(n ~= row)) if (indexLengths(n) > 1) finished = 1; if (n ~= row) % If the first index that is a vector is not the same as specified with % "row" then transpose. If no index is a vector no transposition is done. % If "row" index is no vector but there are two other vectors there % should be an error message there is none. Matrix = Matrix.'; %fprintf('Transposition.\n') end%if end%if n = n +1;end%while
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -