18-6 ��������������������?

fread ƥiqɮפŪGiơA|NC@Ӧ줸լݦ@ӾơAñNGH@x}Ǧ^CҦpAɮ test2.txt epUG

>> type test2.txt This is a test!

fread ŪɮסAiJpUG

Example 1: 18-ɮŪg/fread01.mfid = fopen('test2.txt', 'r'); myData = fread(fid); char(myData') % ҩŪJƬO_T fclose(fid); ans = This is a test!

䤤 char iN myData ন ASCII rA myData muOFϦLXĪG\ŪC

ڭ̥i fread ƪĤGӿJ޼ƨӱǦ^x}jpAҦpG

Example 2: 18-ɮŪg/fread02.mfid = fopen('test2.txt', 'r'); myData = fread(fid, 4) % uŪ 4 Ӧ줸 fclose(fid); myData = 84 104 105 115

myData ׬ 4 VqCPzG

Example 3: 18-ɮŪg/fread03.mfid = fopen('test2.txt', 'r'); myData = fread(fid, [2 3]) fclose(fid); myData = 84 105 32 104 115 105

myData 2X3 x}C

ϥ fread ĤTӿJ޼ơAڭ̥iH fread NGiন MATLAB x}ҥΪTסA]tG

`ΪǫצUCXءG

Hint
L֥Ψ쪺ǫצuint8vΡufloat32vCۦPƦbPxWi줸ơAӥBCإxҥΪǦr곣PAԱAiJuhelp freadvHoPxuWTC

ҦpGY@ɮץ]tƪGiơAhUCOykiHŪ 20 ӪơAöǦ^@ӦVq AG

A = fread(fid, 20, 'long');

bUCdҤAڭ̱N text2.txt Huƪ覡ŪJAyܻA]NOH 16 bit @ӳഫơA]AŪXӪĤ@ӼƦrA|N h M T ഫ 8 bitAbñƦ 16 bitsAMAഫQi쪺ƭȡCdҦpUG

Example 4: 18-ɮŪg/fread04.mfid = fopen('test2.txt', 'r'); myData = fread(fid, 1, 'short') fclose(fid); myData2 = bin2dec([dec2bin(abs('h'),8), dec2bin(abs('T'),8)]) myData = 26708 myData2 = 26708

bWzdҤAnSO`NOGMɮתeӦ줸լO T M hAObH 16 bits @ӳɡAT |O LSB]Least Significant Bits^ h hO MSB]Most Significant Bits^A]ڭ̦Aզ 16 bits ɡAh |be T |bC


MATLAB{]pGJg