13-1 結?????建?

C@ӵc}C]Structure Array^iH]tܦhӤAC@ӤiHݦO@ơC]CӤiH]tƭ]Fields^AӨCi]tUӤPAơCҦp@ӥ]tǥͭӤHƪc}CAitO name]ǥͩmW^Bid]Ǹ^Bscores]pҦZ^CnإߦصcAibOCJ쪺ȡApUG

Example 1: 13-c}C/struct01.mclear student % M student ܼ student.name = 'xP'; % [J name student.id = 'mr871912'; % [J id student.scores = [58, 75, 62]; % [J scores student % qXG student = name: 'xP' id: 'mr871912' scores: [58 75 62]

student YN@ӵc}CĤ@ӤAάOĤ@ơC[JĤGơ]άOĤGӤ^AiJpUG

Example 2: 13-c}C/struct02.mclear student % M student ܼ student.name = 'xP'; % [J name student.id = 'mr871912'; % [J id student.scores = [58, 75, 62]; % [J scores % HUOs[JĤG student(2).name = 'H'; student(2).id = 'mr872510'; student(2).scores = [25, 36, 92]; student % qXG student = 1x2 <a href="matlab:helpPopup struct" style="font-weight:bold">struct</a> array with fields: name id scores

student YN@ 12 c}CCѩ󦹵c}CwͽAMATLAB äNҦȦLXCܬYSwȡAiJTԭzAҦp student(2).scores C

Wz student c}CiϥܦpUG

ܼnameidscores
student(1)'xP''mr871912'[58,75,62]
student(2)'H''mr872510'[25,36,92]

t@ӫإߵc}CkAhOϥ struct OA榡pUG

structureArray = struct(field1, value1, field2, value2,K.)

䤤 field1Bfield2BKOW١Avalue1Bvalue2BKhOҥ]tơCpG value1Bvalue2BK}C]Cell ArraysAԨĤW@^Ah MATLAB |̧DZN}CCӤ]wC@ӵc۹ȡApUG

Example 3: 13-c}C/struct03.mstudent = struct('name', {'ix', 'ixw'}, 'scores', {[50 60], [60 70]}); student(1) % student(1) student(2) % student(2) ans = name: 'ix' scores: [50 60] ans = name: 'ixw' scores: [60 70]

bWzϥΪkA{'ix', 'ixw'} M {[50 60], [60 70]} O}CA]L̪CӤ|Q̦]wCӵcCOpG䤤@ӲȰ}C׬O1A MATLAB |iu¶qi}v]Scalar Expansion^Ӧ۰ʸɨAdҦpUG

Example 4: 13-c}C/struct04.mstudent = struct('name', 'ixw', 'scores', {[50 60], [90 100]}); student(1) % student(1) student(2) % student(2) ans = name: 'ixw' scores: [50 60] ans = name: 'ixw' scores: [90 100]

bWzdҤAuixwvi}C@ӤA]b]w student c}CɡAMATLAB |i¶qi}ANuixwvO]w student Ӥ name ȡC

c}CiHO_]Nested^A]NOAc}CiOt@ӵc}CAڭ̥iHǦͽƵcC|ҨӻAYn[JĤGǥͩҭתҵ{MǤAiUCdҡG

Example 5: 13-c}C/struct05.mstudent = struct('name', {'ix', 'ixw'}, 'scores', {[50 60], [60 70]}); student(2).course(1).title = 'Web Programming'; student(2).course(1).credits = 2; student(2).course(2).title = 'Numerical Method'; student(2).course(2).credits = 3; student(2).course ans = 1x2 <a href="matlab:helpPopup struct" style="font-weight:bold">struct</a> array with fields: title credits

Hint
bWҤAstudent(1).course |۰ʳQw]ůx}C

ڭ̥i@@aإ student c}CApUG

Example 6: 13-c}C/buildStruct01.mclear student % M student ܼ student(1) = struct('name', 'Banny', 'scores', [85,80,92,78]); student(2) = struct('name', 'Joey', 'scores', [80,85,90,88]); student(3) = struct('name', 'Betty', 'scores', [88,82,90,80]);

Wz student c}CAiϥܦpUG


MATLAB{]pGJg