fread ¨ç¼Æ¥i±qÀɮפ¤Åª¨ú¤G¶i¨î¸ê®Æ¡A¥¦·|±N¨C¤@Ӧ줸²Õ¬Ý¦¨¤@Ó¾ã¼Æ¡A¨Ã±Nµ²ªG¥H¤@¯x°}¶Ç¦^¡C¨Ò¦p¡AÀÉ®× test2.txt ªº¤º®e¦p¤U¡G
>> type test2.txt This is a test! ±ý¥Î fread ¨ç¼ÆŪ¨ú¦¹ÀɮסA¥i¿é¤J¦p¤U¡G
¨ä¤¤ char ¥i±N myData ªº¾ã¼ÆÂন ASCII ¦r¤¸¡A¨ú myData ªºÂà¸m¥u¬O¬°¤F¨Ï¦L¥Xªº®ÄªG©ö©ó¾\Ū¡C
§ÚÌ¥i¥Î fread ¨ç¼Æªº²Ä¤GÓ¿é¤J¤Þ¼Æ¨Ó±±¨î¶Ç¦^¯x°}ªº¤j¤p¡A¨Ò¦p¡G
¦¹®É myData ¬°ªø«×¬° 4 ªº¦V¶q¡C¦P²z¡G
¦¹®É myData ¬° 2X3 ªº¯x°}¡C
¨Ï¥Î fread ªº²Ä¤TÓ¿é¤J¤Þ¼Æ¡A§ÚÌ¥i¥H±±¨î fread ±N¤G¶i¨î¸ê®ÆÂন MATLAB ¯x°}©Ò¥Îªººë½T«×¡A¥]§t¡G
- ¤@¦¸Åª¨úªº¦ì¤¸¼Æ¡]Number of Bits¡^
- ³o¨Ç¦ì¤¸¼Æ©Ò¥Nªíªº¸ê®Æ«¬ºA
±`¥Îªººë·Ç«×¦³¤U¦C´XºØ¡G
- char¡G±a²Å¸¹ªº¦r¤¸¡]³q±`¬O 8 bits¡^
- uchar¡G¤£±a²Å¸¹ªº¦r¤¸¡]³q±`¬O 8 bits¡^
- short¡Gµu¾ã¼Æ¡]³q±`¬O 16 bits¡^
- int¡G¾ã¼Æ¡]³q±`¬O 32 bits¡^
- long¡Gªø¾ã¼Æ¡]³q±`¬O 32 ©Î 64 bits¡^
- ushort¡G¤£±a²Å¸¹ªºµu¾ã¼Æ¡]³q±`¬O 16 bits¡^
- uint¡G¤£±a²Å¸¹ªº¾ã¼Æ¡]³q±`¬O 32 bits¡^
- ulong¡G¤£±a²Å¸¹ªºªø¾ã¼Æ¡]³q±`¬O 32 ©Î 64 bits¡^
- float¡G³æºë·Ç¯BÂI¼Æ¡]³q±`¬O 32 bits¡^
- double¡GÂùºë·Ç¯BÂI¼Æ¡]³q±`¬O 64 bits¡^
Ĭ
¨Ò¦p¡GY¦³¤@ÀÉ®×¥]§tªø¾ã¼Æªº¤G¶i¨î¸ê®Æ¡A«h¤U¦C«ü¥O»yªk¥i¥HŪ¨ú 20 Óªø¾ã¼Æ¡A¨Ã¶Ç¦^¤@Ó¦æ¦V¶q A¡G
A = fread(fid, 20, 'long'); ¦b¤U¦C½d¨Ò¤¤¡A§Ú̱N text2.txt ¥Hµu¾ã¼Æªº¤è¦¡Åª¤J¡A´«¥y¸Ü»¡¡A¤]´N¬O¥H 16 bit ¬°¤@Ó³æ¦ì¨ÓÂà´«¦¨¾ã¼Æ¡A¦]¦¹¡AŪ¥X¨Óªº²Ä¤@ӼƦr¡A·|µ¥©ó±N ¡¥h¡¦ ©M ¡¥T¡¦ Âà´«¦¨ 8 bit¡A¦b¨Ã±Æ¦¨ 16 bits¡AµM«á¦AÂà´«¦¨¤Q¶i¦ìªº¾ã¼ÆÈ¡C½d¨Ò¦p¤U¡G
¦b¤Wz½d¨Ò¤¤¡An¯S§Oª`·Nªº¬O¡GÁöµMìÀɮתº«e¨âӦ줸²Õ¬O ¡¥T¡¦ ©M ¡¥h¡¦¡A¦ý¬O¦b¥H 16 bits ¬°¤@Ó³æ¦ì®É¡A¡¥T¡¦ ·|¬O LSB¡]Least Significant Bits¡^ ¦Ó ¡¥h¡¦ «h¬O MSB¡]Most Significant Bits¡^¡A¦]¦¹§Ú̦A«²Õ¦¨ 16 bits ®É¡A¡¥h¡¦ ·|¦b«e¦Ó ¡¥T¡¦ ·|¦b«á¡C
MATLABµ{¦¡³]p¡G¤Jªù½g