18-1 ��������������������?

MATLAB \h{OAiH䴩Uر`ɮ׮榡ŪgAڭ̱Nnɮ׮榡άŪ]μgJ^OzpU]H MATLAB 8.5 D^G

O䴩ɮ׮榡O
@ MAT - MATLAB workspaceload, save
CSV - Comma separated numbers csvread, csvwrite
DAT - Formatted text importdata
DLM - Delimited text dlmread, dlmwrite
TAB - Tab separated text
պ XLS - Excel worksheet xlsread
Ǹ CDF - Common Data Format cdfread, cdfwrite
FITS - Flexible Image Transport System fitsread
HDF - Hierarchical Data Format hdfread, hdfwrite
qv AVI, MPG, WMV, ASF, ASX, MP4, M4V, MOV, etc.videoreader
v TIFF, PNG, HDF, BMP, JPEG, GIF, PCX, XWD, CUR, ICO, RAS, PBM, PGM, PPM, etc. imread, imwrite
T WAV, OGG, FLAC, AU, MP#, M4a, MP4, AU, SND, etc. audioread, audiowrite

HUNwXӱ`ΪOӻC

pG@Ӹɮ׬Oѳr}AӥBu]tƭȸơAhiHϥ csvread OŪɮסAҦpG

Example 1: 18-ɮŪg/csvread01.mfprintf('data.csv eG\n'); type data.csv % CX data.csv e A = csvread('data.csv') % N data.csv eŪx} Adata.csv eG 1, 2, 3 4, 5 6, 7, 8, 9 A = 1 2 3 0 4 5 0 0 6 7 8 9

ѤWzdҥiAcsvread |Ǧ^@Ӽƭȯx}AñNʮuƥH 0 JC

pGƭȸƪɲŸ]Delimiters^OrIANϥ csvread OAӭn dlmread OAҦpG

Example 2: 18-ɮŪg/dlmread01.mfprintf('data.dlm eG\n'); type data.dlm % CX data.dlm e A = dlmread('data.dlm', '\t') % N data.dlm eŪx} Adata.dlm eG 1 2 3 4 5 6 7 8 9 A = 1 2 3 0 4 5 0 0 6 7 8 9

bWzdҤAdata.dlm ƬOHw]Tab^j}A] dlmread OĤGӤ޼ƬO \tAHNwC

pGɮ׸ƥ]tƭȤΦrAڭ̴N textread OAҦpG

Example 3: 18-ɮŪg/textread01.mfprintf('data.txt eG\n'); type data.txt % CX data.txt e [name, hobby, age] = textread('data.txt', '%s%s%d')data.txt eG Timmy OnlineGames 13 Annie Chatrooms 10 Roger Tennis 41 name = 'Timmy' 'Annie' 'Roger' hobby = 'OnlineGames' 'Chatrooms' 'Tennis' age = 13 10 41

bWzdҤAdata.txt ]tT]άOT檺ơ^Atextread iHbĤGӤ޼ƫwƫA]Ҧp %s NrA%d Nơ^AñNŪJƳ]w줣PX޼ơAѩƫAPAX޼Ƥ]PAAHWzdҨӻAname M hobby Or겧Ȱ}CA age hOƭȰ}CC

bWҤAڭ̬OQΪŮӤjApGȥ]ŮAڭ̴NiHҼ{ϥΩwӤjCҦpG

Example 4: 18-ɮŪg/textread02.mfprintf('data2.txt eG\n'); type data2.txt % CX data2.txt e [name, hobby, age] = textread('data2.txt', '%s%s%d', 'delimiter', '\t')data2.txt eG Timmy Online Games 13 Annie Chatrooms 10 Roger Table Tennis 41 name = 'Timmy' 'Annie' 'Roger' hobby = 'Online Games' 'Chatrooms' 'Table Tennis' age = 13 10 41

bWzdҤAڭ̥unb textread OA[Wɦr]Delimiters^wqANiHTaŪXӥѩwҤjɮסC

ϥ textread OAڭ̤]iHŪ@ӤrɡAPɧɮפC@Crܦr겧}C̭C@ӤAҦpG

Example 5: 18-ɮŪg/textread03.mcontents = textread('textread03.m','%s','delimiter','\n','whitespace',''); class(contents) % LX contents O contents{1} % CX contents Ĥ@C contents{2} % CX contents ĤGC ans = cell ans = contents = textread('textread03.m','%s','delimiter','\n','whitespace',''); ans = class(contents) % LX contents O

bWzdҤAڭ̨ϥ textread OŪ textread03.m]]NOdɮס^AܦɮתĤ@CMĤGCC

ƹWAtextread OΪkܦhA\]ܱjjAŪ̥iHJuhelp textreadvNiHo짹㪺޳N䴩C

pGuOnN@ɮתee@ӦrAiHϥ fileread OAdҦpUG

Example 6: 18-ɮŪg/fileread01.mout = fileread('data2.txt'); class(out) size(out) ans = char ans = 1 64

bWzdҤAfileread O|Nɮ data2.txt eerܼ outAclass(out) ȬO charA out ƫAOrAsize(out) hܦr out ׬O 64C

vɮתŪgAŪ̥iHѦҥѲĤQEuvܻPŪgvFTɮתŪgAŪ̥iHѦҥѲĤGQuTŪgBsPvC

pGAɮײŦXp`һ榡ANɶqĨp`ҤЪOӶiŪgCOpGAƮ榡cơANݭn@C@CŪiӡAAiR]Parsing^AONbUCUp`СC


MATLAB{]pGJg