13-4 ������������������

ڭ̥i isstruct OӴլYܼƬO_c}CApU

Example 1: 13-c}C/isstruct01.ms = struct('name', {'Tim', 'Ann'}, 'scores', {[1 3 5 ],[2 4 6]}); isstruct(s) ans = 1

isfield OhiΩլYc}CO_t@SwAҦpG

Example 2: 13-c}C/isfield01.ms = struct('name', {'Tim', 'Ann'}, 'scores', {[1 3 5 ],[2 4 6]}); fprintf('isfield(s, ''name'') = %d\n', isfield(s, 'name')); fprintf('isfield(s, ''height'') = %d\n', isfield(s, 'height')); isfield(s, 'name') = 1 isfield(s, 'height') = 0

bWҤA] s ä]theightAG^Ǽƭ 0C

ڭ̥i cell2struct OӱN}Cഫc}CAҦpG

Example 3: 13-c}C/cell2struct01.mfields = {'name', 'age'}; values = {'Tim', 9; 'Annie', 6}; s = cell2struct(values, fields, 2); s(1) % LXĤ@ s(2) % LXĤG ans = name: 'Tim' age: 9 ans = name: 'Annie' age: 6

bWҤAB⦡us = cell2struct(values, fields, 2)vNO cell2struct Nھڰ}Cܼ fields ƬW١AåH values ĤGӺרӹW fieldsAӲͤ@ӵc}C sCpGH values Ĥ@ӺרӹW fieldsAo쪺GpUG

Example 4: 13-c}C/cell2struct02.mfields = {'name', 'age'}; values = {'Tim', 9; 'Annie', 6}; s = cell2struct(values, fields, 1); s(1) % LXĤ@ s(2) % LXĤG ans = name: 'Tim' age: 'Annie' ans = name: 9 age: 6

cell2struct OSOAΩƮwơCq`ڭ̧QΡuƮwucv]Database Toolbox^qƮwXơAw]ƫAOȰ}CAQ cell2struct OAڭ̴NiH@NאּeBzc}CC

Hint
b MATLAB AYOΦ A2BAjN\ରNܼƥ A ഫ B A䤤Ʀru2vY^utovPrAO٦@int2strBnum2strBstr2numBstr2matBmat2strBbin2decBhex2decBhex2numBbase2decC

dir OiǦ^@c}CA]t{bؿ]θƧ^UUظTAҦpG

Example 5: 13-c}C/dir01.mdirinfo = dir(matlabroot) % rܼ matlabroot N MATLAB ڥؿ dirinfo = 29x1 <a href="matlab:helpPopup struct" style="font-weight:bold">struct</a> array with fields: name date bytes isdir datenum

ѤWiAdirinfo @c}CAtb MATLAB ڥؿUҧtɮשΨLؿTAYW١]name^Aͤ]date^Ajp]bytes^AάO_ؿ]isdir^C


MATLAB{]pGJg