10-2 �ϥΤ@���ܼƨ��x�s�h�Ӧr��

§Ú­Ì¥i¥Î¨âºØ¤èªk¨ÓÀx¦s¦h­Ó¦r¦ê©ó¤@­ÓÅܼƤ§¤¤¡C²Ä¤@ºØ¤èªk¬O¨Ï¥Î¤Gºû¦r¤¸°}¦C¡]Two Dimensional Character Arrays¡^¡A¦ý¥²¶·¥ý½T»{¨C­Ó¦r¦ê¡]§Y¨C¤@¾î¦C¡^ªºªø«×¤@¼Ë¡A§_«h´N¥²¶·¦bµu¦r¦êµ²§À¸É¤WªÅ¥Õ¦r¤¸¡A¥H½T«O¨C¤@¦r¦ê§¡¦³¬Û¦Pªºªø«×¡A¨Ò¦p¡G

Example 1: 10-¦r¤¸»P¦r¦ê/string201.mdepartments = ['ee '; 'cs '; 'econ'] % ª`·N¡u[]¡v¡B¡u;¡v¤ÎªÅ¥Õ¦r¤¸ªº¨Ï¥Î departments = ee cs econ

½Ðª`·N«e­z¤T­Ó¦r¦ê§¡¦U¥Ñ 4 ­Ó¦r¤¸¡]§tªÅ¥Õ¦r¤¸¡^ºc¦¨¡A¬G¨äªø«×§¡¦U¬° 4¡A¦@¦û¥Î°O¾ÐÅé¤j¤p¬°¤G¤Q¥|­Ó¦ì¤¸²Õ¡]§Y 3 ­Ó¦r¦ê¡Ñ4 ­Ó¦r¤¸¡Ñ2 bytes = 24 bytes¡^¡C

²Ä¤GºØ¥iÀx¦s¦h­Ó¦r¦ê©ó¤@­ÓÅܼƪº¤èªk¡A¬O¨Ï¥Î char «ü¥O¡A¨Ò¦p¡G

Example 2: 10-¦r¤¸»P¦r¦ê/string202.mdepartments = char('ee', 'cs', 'econ') % ª`·N¡u()¡v¤Î¡u,¡vªº¨Ï¥Î departments = ee cs econ

¦¹½d¨Ò©Ò±o¨ìªºµ²ªG©M«e¤@­Ó½d¨Ò¬O§¹¥þ¤@¼Ëªº¡C

¦b±q¤Gºû¦r¤¸°}¦C©â¨ú¥X¦r¦ê®É¡A¤Á°O­n¨Ï¥Î deblank «ü¥O¨Ó²¾°£§À³¡ªºªÅ¥Õ¦r¤¸¡A¨Ò¦p¡G

Example 3: 10-¦r¤¸»P¦r¦ê/string203.mdepartments = char('ee', 'cs', 'econ'); dept1 = departments(1,:); % (1,:)¥Nªí²Ä¤@¦Cªº¤¸¯À dept2 = deblank(dept1); % ¨Ï¥Î deblank «ü¥O¨Ó²¾°£§À³¡ªºªÅ¥Õ¦r¤¸ len1 = length(dept1) % Åã¥ÜÅÜ¼Æ dept1 ªºªø«× len2 = length(dept2) % Åã¥ÜÅÜ¼Æ dept2 ªºªø«× len1 = 4 len2 = 2

¦pªG¦r¦êªºªø«×®t²§¬Æ¤j¡A¨º»ò¨Ï¥Î¤Gºû¦r¤¸°}¦C¨ÓÀx¦s¦h­Ó¦r¦ê¡A±N³y¦¨°O¾ÐÅéªÅ¶¡ªº®ö¶O¡C¸Ñ¨M¤§¹D«h¬O¨Ï¥Î¡u²§½è°}¦C¡v¡A¦¹ºØÂí¦C¥D­n¬O¥Î¨ÓÀx¦s¤£¦P«¬ºAªº¸ê®Æ©ó¦P¤@­ÓÅܼƤº¡A¥»®Ñ²Ä¤Q¤G³¹¦³±M³¹¸Ô²Ó¤¶²Ð¡A¦b¦¹¶È§@»P¥»¸`¦³ÃöªºÂ²³æ»¡©ú¦p¤U¡G

Example 4: 10-¦r¤¸»P¦r¦ê/string204.mcellData = {'ee', 'cs', 'econ'}; % ¥H²§½è°}¦C celldata ¨ÓÀx¦s¦h­Ó¦r¦ê dept = cellData{3} % ¦L¥X²Ä¤T­Ó¦r¦ê¡]¥²¶·¨Ï¥Î¤j¬A¸¹¡^ dept = econ

§Ú­Ì¥i¨Ï¥Î cellstr «ü¥O±N¦r¤¸°}¦CÂà´«¦¨²§½è°}¦C¡G

Example 5: 10-¦r¤¸»P¦r¦ê/string205.mdepartments = char('ee', 'cs', 'econ'); cellData = cellstr(departments); leng = length(cellData{2}) % Åã¥Ü²§½è°}¦C cellData ²Ä¤G­Ó¤¸¯Àªø«× leng = 2

¦b¤W¨Ò¤¤¡Acellstr «ü¥O¨Ó±N¦r¤¸°}¦C departments Âà´«¦¨²§½è°}¦C cellData Àx¦s¡A¦Ó­ì¥ý¸É¦b¦r¤¸°}¦C departments µ²§ÀªºªÅ¥Õ¦r¤¸¡A¤w³Q²¾°£¡A¦]¦¹ leng ªº­È¬° 2¡C

­Y­n±N¥]§t¦r¦êªº²§½è°}¦CÂà´«¦¨¤@¯ëªº¤Gºû¦r¤¸°}¦C¡AÁÙ¬O¥i¥H¨Ï¥Î char «ü¥O¡A¨Ò¦p¡G

Example 6: 10-¦r¤¸»P¦r¦ê/string206.mdept1 = char('ee', 'cs', 'econ'); % dept1 ¬O¤@­Ó¦r¤¸°}¦C cellData = cellstr(dept1); % ±N dept1 Âন¤@­Ó²§­È°}¦C cellData dept2 = char(cellData); % ±N cellData Âà´«¦¨¦r¤¸°}¦C dept2 isequal(dept1, dept2) % ´ú¸Õ dept1 ©M dept2 ¬O§_¬Ûµ¥ ans = 1


MATLABµ{¦¡³]­p¡G¤Jªù½g