2-7 �u�@�Ŷ��P�ܼƪ��x�s�θ��J

MATLAB ¦b¶i¦æ¦UºØ¹Bºâ®É¡A·|±NÅܼÆÀx¦s¦b°O¾ÐÅ餺¡A³o¨ÇÀx¦sÅܼƪº°O¾ÐÅéªÅ¶¡ºÙ¬°°ò¥»¤u§@ªÅ¶¡¡]Base Workspace¡^©Î²ºÙ¤u§@ªÅ¶¡¡]Workspace¡^¡C·í¨C¦¸ MATLAB ©I¥s°õ¦æ¬Y¤@¨ç¼Æ®É¡A§Y¶i¤J¸Ó¨ç¼Æªº¼È®É¤u§@ªÅ¶¡¡]©Î¥iµø¬°¬O¬Û¹ï©ó°ò¥»¤u§@ªÅ¶¡ªº¤U¼h¼È®É¤u§@ªÅ¶¡¡^¡A¨ç¼Æ¥i¦b¦¹¼È®É¤u§@¶¡¤º²£¥Í¦UºØÅܼƨöi¦æ¹Bºâ¡A¦Ó¤£·|¼vÅT¨ì°ò¥»¤u¶¡ªÅ¶¡¤ºªºÅܼơC·í¨ç¼Æ°õ¦æµ²§ô®É¡AMATLAB ·|¦P®É§R°£¨ç¼Æªº¼È®É¤u§@ªÅ¶¡¡]·íµM¤]·|§R°£Àx¦s©ó¨ä¤ºªº©Ò¦³Åܼơ^¡A¨Ã¦^¨ì MATLAB ªº°ò¥»¤u§@ªÅ¶¡¡C¥H¤U²­z´X­Ó¦³Ãö¤u§@ªÅ¶¡ªº«ü¥O¡C

­Y­nÀ˵ø²{¦s©ó¤u§@ªÅ¶¡¡]Workspace¡^ªºÅܼơA¥iÁä¤J who¡G

>> who Your variables are: A ans s x z B i t y

¦b¤W¨Ò¤¤¡A¥uÅã³o¨Ç¬O¥Ñ¨Ï¥ÎªÌ©w¸qªºÅܼƪº¦WºÙ¡C­Y­nª¾¹D³o¨ÇÅܼƧó¸Ô²Óªº¸ê®Æ¡]¨Ò¦p¡GÅܼƥe¥Îªº°O¾ÐÅé¤j¤p¡B¤Î¨äÀx¦sªº¸ê®Æ«¬ºA§O¡^¡A«h¥i¨Ï¥Î whos «ü¥O¡A¨Ò¦p¡G

>> whos Name Size Bytes Class A 2x4 64 double array B 1x3 24 double array ans 1x18 36 char array i 1x1 8 double array s 1x4 32 double array t 1x5 40 double array x 1x6 48 double array y 1x1 8 double array z 1x1 16 double array (complex) Grand total is 47 elements using 276 bytes

Hint
À˵ø¤u§@ªÅ¶¡Åܼƪº¨ä¥L¤è¦¡¡G¦b MATLAB ©R¥Oµøµ¡¤ºª½±µ¿é¤J workspace «ü¥O¡A¥ç¥i¹F¨ìÀ˵ø¤u§@ªÅ¶¡ªºÅܼƮĪG¡C

¦P®É¤]¥i¥H¨Ï¥Î clear «ü¥O¨Ó²M°£©Î§R°£¤u§@ªÅ¶¡¤ºªº¬Y¤@¯S©w©Î©Ò¦³ÅܼơA¥HÁקK°O¾ÐÅ骺¶¢¸m»P®ö¶O¡G

>> clear A % §R°£¤u§@ªÅ¶¡¤ºªºÅÜ¼Æ A >> clear all % §R°£¤u§@ªÅ¶¡¤ºªº©Ò¦³ÅܼÆ

­È±oª`·Nªº¬O¡AMATLAB ¦³¨Ç¥Ã¤[±`¼Æ¡]Permanent Constants¡^¡AÁöµM¦b¤u§@ªÅ¶¡¤¤¬Ý¤£ ¨ì¡A¦ý¨Ï¥ÎªÌ¥iª½±µ¨ú¥Î¡A¨Ò¦p¡G

>> pi ans = 3.1416

±`¨Ï¥Î¨ìªº MATLAB ªº¥Ã¤[±`¼Æ¡A¥i¦C¥X¦p¤U¡G

±`¼Æ »¡©ú
i ©Î j°ò¥»µê¼Æ³æ¦ì¡]§Y $\sqrt{-1}$¡^
eps¨t²Îªº¯BÂI¡]Floating-point¡^ºë½T«×
infµL­­¤j¡]§Y $\infty$¡^¡A ¨Ò¦p¡G1/0
nan ©Î NaN«D¼Æ­È¡]Not A Number¡^¡A¨Ò¦p¡G0/0
pi¶ê©P²v¡]= 3.1415926...¡^
realmax¨t²Î©Ò¯àªí¥Üªº³Ì¤j¼Æ­È
realmin¨t²Î©Ò¯àªí¥Üªº³Ì¤p¼Æ­È
nargin¨ç¼Æªº¿é¤J¤Þ¼Æ­Ó¼Æ
nargout¨ç¼Æªº¿é¥X¤Þ¼Æ­Ó¼Æ

¦b¤j¶qªø®É¶¡°õ¦æ MATLAB ¹Bºâ¤¤¡A¨Ï¥ÎªÌ³q±`§Æ±æ¯à±N­pºâ©Ò±o¦UÅܼƤº®eÀx¦s¦bÀɮפ¤¡]¤@¯ë·|¼È®ÉÀx¦s¦b¤u§@ªÅ¶¡¤º¡^¡A¥H«K±N¨Ó¥i­«·s¸ü¤J¥H¶i¦æ¨ä¥L³B²z¡C¦¹®É¡A¨Ï¥ÎªÌ¥i¥Î save «ü¥OÀx¦sÅܼƤº®e¨ìÀɮסA¦Ó«á¦A¥Î load «ü¥O±NÀɮתº¤º®e¸ü¤J¨ì¤u§@ªÅ¶¡¥H¶i¦æ¨ä¥L³B²z¡A¥H¤U¨Ì¦¸¤À­z¤§¡C

¦b¤£¥[¥ô¦ó¿ï¶µ¡]Options¡^®É¡Asave «ü¥O·|±N¤u§@ªÅ¶¡¤ºªºÅܼƥH¤G¶i¨î¡]Binary¡^ªº¤è¦¡Àx¦s¦Ü°ÆÀɦW¬° mat ªºÀɮסG

­º¥ý§Ú­Ì¥ý¸õ¨ì¥»³¹ªº½d¨Ò¥Ø¿ý¡G

>> cd 'd:\matlabBook\MATLABµ{¦¡³]­p¡G¤Jªù½g\02-ªì±´MATLAB'

¥H¤U¬°¨Ï¥Î save «ü¥Oªº¤@­Ó¨Ò¤l¡G

>> clear all % ²M°£¤u§@ªÅ¶¡¤ºªº©Ò¦³ÅÜ¼Æ >> x = 10; y = [1, 2, 3]; % x, y ¬°·sÅÜ¼Æ >> whos % ¦C¥X¤u§@ªÅ¶¡¤º©Ò¦³ÅÜ¼Æ Name Size Bytes Class x 1x1 8 double array y 1x3 24 double array Grand total is 4 elements using 32 bytes >> save test x y % ±NÅÜ¼Æ x »P y Àx¦s¦Ü test.mat >> dir *.mat % ¦C¥X¥Ø«e¤u§@¥Ø¿ý¤¤ªº©Ò¦³ MAT ÀÉ®× test.mat >> delete test.mat % §R°£ÀÉ®× test.mat

¥H¤G¶i¨îªº¤è¦¡Àx¦s¤u§@ªÅ¶¡ªºÅܼơA³q±`ÀÉ®×·|¤ñ¸û¤p¡A¦Ó¥B¦b¸ü¤J®É³t«×¸û§Ö¡A¯ÊÂI¬OµLªk¥Î´¶³qªº¤å®Ñ³nÅé¡]¨Ò¦p¡GMS Word ©Î°O¨Æ¥»¡^¨ÓÀ˵øÀɮפº®e¡C

­Y·Q¬Ý¨ìÀɮפº®e¡A«h¥²»Ý¥H ASCII ªºÀɮ׮榡¨ÓÀx¦s¤u§@ªÅ¶¡ªºÅܼơG

¦b save «ü¥O¨Ï¥Î ¡Vascii ¿ï¶µ«á¡A·|¦³¤U¦C²{¶H¡G

¤@¯ë¦Ó¨¥¡A¥H¤G¶i¨î©ÒÀx¦sªºÀɮסA¦bŪ¨ú®É·|¤ñ¸û§Ö¡A©Ò¦ûªºªÅ¶¡¤]¤ñ¸û¤p¡A©Ò¥H§Ú­ÌÀ³¸ÓºÉ¶q¥H¤G¶i¨î¤è¦¡Àx¦s¸ê®Æ¡C

¦b±N¤u§@ªÅ¶¡ªºÅܼÆÀx¦s©óÀɮ׫á¡A¨Ï¥Î load «ü¥O¥i±N¸ÓÀɮשÒÀx¦s¤§ÅܼƸü¤J¤u§@ªÅ¶¡¡A¨ä®æ¦¡¦p¤U¡G

­Y¥H ASCII ®æ¦¡¸ü¤J¡A«hÅܼƦWºÙ§Y¬°ÀɮצWºÙ¡]¦ý¤£¥]§t°ÆÀɦW¡^¡C­Y¥H¤G¶i¨î¸ü¤J¡A«h¥i«O¯d­ì¦³ªºÅܼƦWºÙ¡A¨Ò¦p¡G

>> clear all; % ²M°£¤u§@ªÅ¶¡¤¤ªºÅÜ¼Æ >> x = 1:10; >> save testfile.dat x -ascii % ±N x ¥H ASCII ®æ¦¡¦s¦Ü¦W¬° % testfile.dat ªºÀÉ®× >> load testfile.dat % ¸ü¤J testfile.dat >> who % ¦C¥X¤u§@ªÅ¶¡¤¤ªºÅÜ¼Æ Your variables are: testfile x

ª`·N¦b¤W­z¹Lµ{¤¤¡A¥Ñ©ó¬O¥H ASCII ®æ¦¡Àx¦s»P¸ü¤J¡A©Ò¥H²£¥Í¤F¤@­Ó»PÀɮצWºÙ¬Û¦PªºÅÜ¼Æ testfile¡A¦¹Åܼƪº­È©M­ìÅÜ¼Æ x §¹¥þ¬Û¦P¡C

Hint
¦pªG§A¤ñ¸û²ßºD¨Ï¥Î¹Ï§Î¤¶­±¨Ó¶i¦æ¸ê®Æ¶×¤J¡A¥i¥Ñ MATLAB ®à­±ªº¡uFile/Import Data...¡v¨Ó¶i¦æ¡C

¦³Ãö MATLAB ¹ï©óÀɮתºÅª¼g¥\¯à¡AŪªÌ¥i¸Ô¨£²Ä¤Q¤K³¹¡uÀɮ׿é¥X¤Î¿é¤J¡v¡C


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