12-4 ?????令

Ynƥtm]Pre-Allocate^Ū}CAi cell OAҦpG

Example 1: 12-}C/cellAllocate01.mE = cell(4, 3) % ƥtm@ 43 Ū}C E = [] [] [] [] [] [] [] [] [] [] [] []

YnլY@ܼƬO_}CAi iscell OAҦpG

Example 2: 12-}C/iscell01.mC = {[1,2,3]; 'This is a test.'}; iscell(C) ans = 1

bWҤAiscell O浲GOǦ^ 1ANܼ A O@Ӳ}CAYǦ^ 0AhNO}CC

Hint
b MATLAB AHisrOjO˵OAY˵GuAh^Ǽƭ 1A_hN^Ǽƭ 0AO ischarBisstrBisnumericBisobjectBissparseBisnanBisfiniteBisinfBiscellstrBisvarnameBiskeyword C

num2cell OiN@ƭȰ}Cഫ}CA ϥλykG

C = num2cell(A, dim)

䤤 dim ON uQΡvסAYwAhNCӤ}C̭@ 11 x}AҦpG

Example 3: 12-}C/num2cell01.mA = [1 2 3;4 5 6]; % إߪ@ӼƭȰ}C A C = num2cell(A) % NƭȰ}C A ন}C C C = [1] [2] [3] [4] [5] [6]

YnNƭȰ}C A C@A ন}C D AiJpUG

Example 4: 12-}C/num2cell02.mA = [1 2 3;4 5 6]; % إߪ@ӼƭȰ}C A D = num2cell(A, 1) % 1 NuCQΡv D = [2x1 double] [2x1 double] [2x1 double]

NƭȰ}C A C@CA ন}C E AiJpUG

Example 5: 12-}C/num2cell03.mA = [1 2 3;4 5 6]; % إߪ@ӼƭȰ}C A E = num2cell(A, 2) % 2 NuQΡv E = [1x3 double] [1x3 double]

struct2cell OiN@c}CҦഫ}CC]󵲺c}CAаѦҥѤU@uc}CvC^ҦpG

Example 6: 12-}C/struct2cell01.mstudent.name = 'Tim'; student.age = 8; sCell = struct2cell(student) sCell = 'Tim' [8]

t~@ cell2struct OAiHNȰ}Cഫc}CAԲӻаѦҥѪU@uc}CvC

YN@c}CY@ഫ}CAiϥ deal OAҦpG

Example 7: 12-}C/deal01.mS = struct('name',{'Tim','Annie'},'age', {8,5}); [sCell{1:length(S)}] = deal(S.name) sCell = 'Tim' 'Annie'

deal OJοXޭzݦۦPӼơA]bWҤAsCell{1:length(S)} @ΧYOͥHrI}XܼƦCC deal OAiFƥb\ġAҦpACX MATLAB ڥؿUҦؿ]tɮס^AiXpUG

Example 8: 12-}C/deal02.mdirInfo = dir(matlabroot); % CX MATLAB ڥؿUظT n = length(dirInfo); % ɮפΥؿӼ [fileAndDir{1:n}] = deal(dirInfo.name); % fileAndDir ]tUɮפΥؿW dirs = fileAndDir([dirInfo.isdir]) % dirs ]tUؿW dirs = Columns 1 through 6 '.' '..' 'appdata' 'bin' 'bugreport' 'etc' Columns 7 through 11 'examples' 'extern' 'help' 'java' 'lib' Columns 12 through 16 'licenses' 'mcr' 'notebook' 'polyspace' 'remote' Columns 17 through 21 'resources' 'rtw' 'runtime' 'simulink' 'stateflow' Columns 22 through 25 'sys' 'toolbox' 'ui' 'uninstall'


MATLAB{]pGJg