⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nshape.m

📁 多维数据处理:MATLAB源程序用于处理多维数据
💻 M
字号:
function [X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13,X14,X15,X16,X17]=nshape(X,DimX,f);

% $ Version 1.03 $ Date 18. July 1999 $ Not compiled $
% $ Version 1.031 $ Date 18. July 1999 $ Error in help figure and now outputs new DimX $ Not compiled $
%
% Copyright, 1998 - 
% This M-file and the code in it belongs to the holder of the
% copyrights and is made public under the following constraints:
% It must not be changed or modified and code cannot be added.
% The file must be regarded as read-only. Furthermore, the
% code can not be made part of anything but the 'N-way Toolbox'.
% In case of doubt, contact the holder of the copyrights.
%
% Rasmus Bro
% Chemometrics Group, Food Technology
% Department of Food and Dairy Science
% Royal Veterinary and Agricultutal University
% Rolighedsvej 30, DK-1958 Frederiksberg, Denmark
% Phone  +45 35283296
% Fax    +45 35283245
% E-mail rb@kvl.dk
%
%
% [Xf,DimXf] = nshape(X,DimX,f);
%
% Refolds an N-way array so that Xf is X with index
% f as row-index, and the remaining in succesive order. For an 
% I x J x K x L four-way array this means X1 is I x JKL, X2 is
% J x 蘇L, X3 is K x IJL, and X4 is L x IJK
%
%
%    K  _______             
%      /      /|           1      J     2稪    J稫
%     /______/ |         1  _____________________
%    |      |  |           |      |      |      |
%    |      | /    -->     |      |      |      |        f = (Mode) 1 (same as original array)
% I  |______|/          I  |______|______|______|
%           J
%
%                          1      I     2稩    K稩
%                        1  _____________________
%                          |      |      |      |
%                  -->     |      |      |      |        f = (Mode) 2
%                        J |______|______|______|
%
%  
%                          1      I     2稩    I稪
%                        1  _____________________
%                          |      |      |      |
%                  -->     |      |      |      |        f = (Mode) 3
%                        K |______|______|______|
%
%
% If the last input is not given all rearrangements are given.
% For a fourway array this would read
% [X1,X2,X3,X4]=nshape(X,DimX);
%
%	Copyright
%	Rasmus Bro & Claus A. Andersson 1995
%	Denmark
%	E-mail rb@kvl.dk

ord=chkpfdim(X,DimX,NaN);
elemen=prod(DimX);
if nargin==2
  do_it=ones(1,ord);
else
  do_it=zeros(1,ord);
  do_it(f)=1;
end

if do_it(1)==1
  X1=X;
end


% _____Make X2_____

if do_it(2)==1
  X2=X(:,1:DimX(2)).';
  for R2=DimX(2)+1:DimX(2):elemen/DimX(1)
    X2=[X2 X(:,R2:R2+DimX(2)-1).'];
  end
end

if ord>3

% _____Make X3 - Xord-1_____

for comp=3:ord-1
  if do_it(comp)==1
    xx=[];  % Denne kan opbygges til flere
    for R2=1:prod(DimX(2:comp-1)):prod(DimX(2:comp))
      x=[];
      for R3=R2:prod(DimX(2:comp)):prod(DimX(2:ord))
        x=[x reshape(X(:,R3:R3+prod(DimX(2:comp-1))-1),1,prod(DimX(1:comp-1)))];
      end % for
      xx=[xx;x];
    end
    eval(['X',num2str(comp),'=xx;']);
  end % for comp
end
end % if ord>3


% _____Make Xord_____

if do_it(ord)==1
  xx=[];
  for R3=1:elemen/(DimX(1)*DimX(ord)):elemen/DimX(1)
    xx=[xx; reshape(X(:,R3:R3+elemen/(DimX(1)*DimX(ord))-1),1,elemen/DimX(ord))];
  end % for
  eval(['X',num2str(ord),'=xx;']);
end

if nargin==3
   eval(['X1=X',num2str(f),';']);
   X2 = [DimX(f) DimX([1:f-1 f+1:ord])];
end

⌨️ 快捷键说明

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