10-4 rBƭȻP}C�

int2str «ü¥O¥i±N¾ã¼Æ«¬ºAªº¸ê®ÆÂà´«¦¨¦r¦ê¸ê®Æ¡A¨Ò¦p¡G

Example 1: 10-¦r¤¸»P¦r¦ê/string401.mx = 13462; y = int2str(x) % ±N¾ã¼Æ«¬ºAªº¸ê®ÆÂà´«¦¨¦r¦ê¸ê®Æ length(y) % À˵ø y ªºªø«× y = 13462 ans = 5

¦b¤W¨Ò¤¤¡A­ì¥ýÅÜ¼Æ x Àx¦s¤@­Ó¾ã¼Æ 13862¡Aint2str «ü¥O±N¨äÂà´«¦¨¤@­Ó¦r¦ê "13462"¡A¨äªø«×¬° 5 ­Ó¦r¤¸¡C

­Y­n±N¹ê¼ÆÂର¦r¦ê¡A¥i¥Î num2str «ü¥O¡A¨Ò¦p¡G

Example 2: 10-¦r¤¸»P¦r¦ê/string402.mstr1 = num2str(pi) % ¹ê¼ÆÂର¦r¦ê¡A¹w³]¦³®Ä¦ì¼Æ¬O 4 ¦ì str2 = num2str(pi, 10) % ¼W¥[¤p¼Æ¥H¤U¦³®Ä¦ì¼Æ¨ì 10 ¦ì str1 = 3.1416 str2 = 3.141592654

int2str ¤Î num2str ±`¥Î©ó¼Ð¥Ü®y¼ÐÂIªº­È¡A¨Ò¦p¡G­Y­n¦by = sin(x) ªº¹Ï§Î¤W¡A¼Ð¥X·í x = 2.5 ªº®y¼Ð­È¡A¥i¿é¤J¦p¤U¡G

Example 3: 10-¦r¤¸»P¦r¦ê/string403.mx = 0:0.1:2*pi; y = sin(x); plot(x,y) str = ['\leftarrow (', num2str(2.5), ', ', num2str(sin(2.5)), ')']; text(2.5, sin(2.5), str)

dec2hex «ü¥O¥i±N 10 ¶i¦ì¼Æ­È¸ê®ÆÂà´«¦¨ 16 ¶i¦ìªº¦r¦êªí¥Üªk¡A¨Ò¦p¡G

Example 4: 10-¦r¤¸»P¦r¦ê/string404.mx = 1026; y = dec2hex(x) y = 402

½Ðª`·N¦b¤W¨Ò¤¤¡AÅÜ¼Æ x Àx¦s¸ê®Æ«¬ºA¬°¼Æ­È¡A¦ÓÅÜ¼Æ y Àx¦s¸ê®Æ«¬ºA¬°¦r¦ê¡CÃþ¦üªº«ü¥OÁÙ¦³ hex2num¡Bhex2dec¡Bdec2hex¡Bbin2dec¡Bdec2bin¡B base2dec µ¥¡A½Ð¥Î help «ü¥O¬d¾\¨ä¦U¦Û¨Ï¥Î»yªkªº¸Ô²Ó»¡©ú¡A¦b¦¹¤£¦AÂØ­z¡C

mat2str «ü¥O¥i±N¯x°}Âà´«¬°¦r¦ê¡A¦¹¦r¦ê­Y¦A¸g¥Ñ eval «ü¥Oªº¨Ï¥Î¡A¥i¦AÅܦ^­ì¥ýªº¯x°}¡A¨Ò¦p¡G

Example 5: 10-¦r¤¸»P¦r¦ê/string405.mA = [1 2 1; 3 5 6 ]; B = mat2str(A) % ±N¯x°} A Âন¦r¦ê B A2 = eval(B); % ¦A±N¦r¦ê B Âà¦^¯x°} A2 isequal(A, A2) % ´ú¸Õ A ©M A2 ¬O§_¬Ûµ¥ B = [1 2 1;3 5 6] ans = 1

¦b¤W¨Ò¤¤¡A mat2str «ü¥O¤w±N¬° 2¡Ñ3 ªº¼Æ­È¯x°} A Âà´«¡AÅܦ¨¤Gºû¦r¦ê°}¦C B¡AµM«á¦A¹ï¦¹¤Gºû¦r¦ê°}¦C B ¨Ï¥Î eval «ü¥O¡A²£¥Í¤@­Ó»PÂà´««eªº¯x°} A ¬Û¦P¤º®eªº¯x°} A2¡C

sprintf «ü¥O¥iµ²¦X¼Æ­È©Î¦r¦ê¡A¥H²£¥Í·s¦r¦ê¡A¨Ò¦p¡G

Example 6: 10-¦r¤¸»P¦r¦ê/string406.mstr = '¶ê©P²v'; newString = sprintf('¡u%s¡v¬O %g', str, pi) newString = ¡u¶ê©P²v¡v¬O 3.14159

¨ä¤¤ %s ¥Nªí¦L¥X¦r¦ê¡A%g ¥Nªí¦L¥X¼Æ­È¡A¥ç¥i¨Ï¥Î %f ©Î¥[¤W±±¨î¦L¥X¦ì¼Æ¤j¤pªº¼Æ¦rµ¥¡A¥Hºë½Tªº±±¨î²£¥Íªº¦r¦ê®æ¦¡¡A¸Ô±¡½Ð¬d¾\ help sprintf ªº»¡©ú¡C

sscanf ¥i¨Ìµ¹©wªº®æ¦¡¨Ó¸ÑªR¥X©Ò­nªº¦r¦ê©Î¼Æ­È¡A¨Ò¦p¡G

Example 7: 10-¦r¤¸»P¦r¦ê/string407.mstr = '2 4.7 5.2'; mat = sscanf(str, '%f') mat = 2.0000 4.7000 5.2000

Hint
sprintf ©M sscanf ©Ò¥Îªº®æ¦¡±±¨î¤è¦¡§¡©M C »y¨¥¤¤ªº printf ©M scanf ¬Û·í¤@­P¡C


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