||
使用场景:如果我们想把一个矩阵分块进行计算,而每块的大小并不一定相同时,可以使用该函数
形式:
C = mat2cell(A, dim1Dist, …, dimDist)
C = mat2cell(A, rowDist)
参数解释:
Divide the 5-by-4 matrix X into 2-by-3 and 2-by-2 matrices contained in a cell array. X = reshape(1:20,5,4)' C = mat2cell(X, [2 2], [3 2]) celldisp(C) This code returns X = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 C = [2x3 double] [2x2 double] [2x3 double] [2x2 double] C{1,1} = 1 2 3 6 7 8 C{2,1} = 11 12 13 16 17 18 C{1,2} = 4 5 9 10 C{2,2} = 14 15 19 20 % ----------------------------------------------- Divide X (created in the previous example) into a 2-by-1 cell array. C = mat2cell(X, [1 3]) celldisp(C) This code returns C = [1x5 double] [3x5 double] C{1} = 1 2 3 4 5 C{2} = 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2025-1-7 05:05
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社