mymat2cell.m

来自「Continuous Profile Models (CPM) Matlab T」· M 代码 · 共 52 行

M
52
字号
function c = mymat2cell(m,rowSizes,colSizes)%MYMAT2CELL.M Break matrix up into a cell array of matrices.%%	Synopsis%%	  mymat2cell.m(M,R,C);%%	Description%%	  MYMAT2CELL.M(M,R,C) takes three arguments,%	    M - ROWxCOL Matrix.%	    R - Vector of row sizes (should sum to ROW).%	    C - Vector of col sizes (should sum to COL).%	  and returns a cell array of matrices, found using R and C.%%	Example%%	   M = [1 2 3 4; 5 6 7 8; 9 10 11 12];%	   C = mymat2cell.m(M,[1 2],[2 2])%	    %	See also CELL2MATswitch nargin  case 1,    c = {m};    case 2,    rows = length(rowSizes);    c = cell(rows,1);    rowStart = 0;    for i=1:rows      c{i,1} = m(rowStart+[1:rowSizes(i)],:);      rowStart = rowStart + rowSizes(i);    end	  case 3,    rows = length(rowSizes);	cols = length(colSizes);    c = cell(rows,cols);    rowStart = 0;    for i=1:rows	  colStart = 0;	  for j=1:cols        c{i,j} = m(rowStart+[1:rowSizes(i)],colStart+[1:colSizes(j)]);        colStart = colStart + colSizes(j);	  end      rowStart = rowStart + rowSizes(i);    endend

⌨️ 快捷键说明

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