Sie sind auf Seite 1von 43

Who's the Boss?

IAP 2009 Scott Gorlin gorlins@mit.edu

http: stell!r.mit.edu S pro"ect !d#!nced$m!tl!%

Wor&'lo(
)

*!tl!% is gre!t 'or d!t! !n!l+sis, %ut) .irst h!#e to get d!t! I/ to *!tl!%0

1!#e to get d!t! 234


) 5ither !s 'igure or !n!l+6ed d!t!

Sometimes need other !pplic!tions to do our (or&

7!t! .orm!ts
)

*!tl!% n!ti#e
) Propriet!r+ 8.m!t 'iles ) *ostl+ incomp!ti%le (ith other progr!ms ) 9!n s!#e 'igures plots !s "pg, %ut sometimes this is not enough

7!t! .orm!ts
)

4ric& :;
) 5<port 'igures !s 8.em' or 8.!i 8.eps
) 5nh!nced *et!'ile 'or *S !pplic!tions li&e PP4 ) Ado%e Illustr!tor or 5nc!psul!ted Postscript 'orm!t 'or !n+thing else ) 4hese !re =5942> 'orm!ts
) ) ) )

*uch higher resolution, lo(er 'ilesi6e Better colors ?*!tl!% is ! poor @PG rendererA 5dit!%le in Word Illustr!tor 3se P/G 4I.. i' +ou !%solutel+ need ! r!ster im!ge

7!t! .orm!ts
)

AS9II 7!t!
) Applic!tion stores d!t! in ! te<t 'ile ) >eg!rdless o' e<tension, +ou c!n #ie( in Wordp!d ) 9S=
) /um;, num2, numB etc

) 4AB
) /um; num2 numB etc

) And other 'orm!ts

7!t! .orm!ts
)

AS9II 7!t!
) *ost o' these c!n %e directl+ imported through the (or&sp!ce ) Also see importdata, textread, !nd help 'or C.ile .orm!tsD

7!t! .orm!ts
)

.!ils!'e (!+ to get d!t! into *!tl!%:


) 9op+ into 5<cel spre!dsheet ) >e!d spre!dsheet in *!tl!% (ith xlsread

7!t! .orm!ts
)

AS9II 7!t! E Some *A@2> pro%lems


) 7!t! is much l!rger on dis& th!n it needs to %e
) 9!n %e F;0< l!rger, !t le!st, th!n !n optimi6ed 'orm!t ) ; %+te ch!r G 2HH #!lues, %ut (e use I ;00 o' them
)

0$9 'or numeric, A$J,!$6 'or ch!rs, ne#er 0@:KL8A: etc

) Sometimes 2 %+tes ch!r F MH000 unused #!lues0

) 2nl+ good 'or ch!rs or simple sets o' m!trices E not !l(!+s !ppropri!te ) Sometimes +ou "ust c!nDt get it 'rom +our progr!m0

7!t! .orm!ts
)

Bin!r+ 7!t!
) 2ptimi6ed 'ile use
) *uch sm!ller E d!t! descri%ed e<!ctl+ (ith %its, inste!d o' in te<t strings ) Applic!tion c!n (rite its o(n 'orm!t
)

.iles !lmost !l(!+s n!ti#el+ %in!r+

) 9!nDt %e #ie(ed (ith Wordp!d, so (e h!#e to tr!nsl!te it into *!tl!%

7!t! .orm!ts
)

Bin!r+ 7!t!
) Sometimes 'orm!t is propriet!r+
) 9omp!n+ m!+ pro#ide ! re!ding utilit+ S7N, ie ! dll, (hich c!n %e sourced in *!tl!% or other ) /ot e#er+ propriet!r+ 'orm!t is possi%le to re!d into *!tl!%, unless +ou h!c& it

7!t! .orm!ts
)

Bin!r+ 7!t!
) *!n+ !pplic!tions (ill use !n open source or pu%lished 'orm!t to store d!t! ) All (e need to do is 'ind the source document!tion, !nd (e c!n (rite ! *!tl!% 'unction to re!d in the d!t! 'ile0

7!t! .orm!ts
)

.inding 'orm!t document!tion


) Sometimes ! help 'ile descri%es the %in!r+ 'orm!t o' d!t! ) 3su!ll+, (ith progr!ms (ritten in 9 ?most !reA, ! structure definition is pro#ided in ! header file

7!t! .orm!ts
)

.inding 'orm!t document!tion


) Structure de'inition
) Structures in 9 !re li&e structures in *!tl!% E cont!in ! set o' rel!ted d!t! E %ut the+ !re usu!ll+ sc!l!r, not structure m!trices ) In 9, ! structure must %e de'ined ?%ec!use o' st!tic memor+ !lloc!tionA !nd this is usu!ll+ done in ! Che!der 'ileD (ith ! n!me li&e Cd!t.hD, d!t %eing the e<tension o' the d!t! 'ile cre!ted ) 3su!ll+ ! d!t!'ile is nothing %ut this structure (ritten to dis&, e<!ctl+ ho( the structure is de'ined

7!t! .orm!ts
)

.inding 'orm!t document!tion


) 2'ten, 'or common d!t! 'orm!ts, +ou (ill "ust %e pro#ided (ith the he!der 'ile0
) 2r +our progr!m m!+ list the he!der 'ile in !n !ppendi<, e#en i' it is not open source

) /I'4I is ! common 'orm!t 'or *>I #olume d!t!, http: ni'ti.nimh.nih.go#

/ii 5<!mple
)

/I'4I $ 8.nii 'iles 'or '*>I

) .orm!t is documented in ni'ti;.h, pro#ided on Stell!r site !nd distri%uted %+ /I*1 ) OetDs (!l& through this e<!mple to see ho( to re!d ! custom d!t! 'orm!t) 8.h 'iles !re te<t, %ut *!tl!% c!n color &e+(ords "ust li&e in m$'iles

) .ile $P Pre'erences $P 5ditor 7e%ugger $P O!ngu!ges ) Select 9 9QQ !nd ensure th!t .h is included in .ile 5<tensions

/ii 5<!mple
)

*uch o' the he!der is 9 code (e c!n ignore


) Green is document!tion, commented (ith 8 -. 8 'or %loc& comments or

/ii 5<!mple
)

>e!ding the document!tion, (e disco#er th!t ! 8.nii 'ile cont!ins the 'ollo(ing, in order:
) A Che!derD descri%ing the d!t! ) An+ num%er o' option!l Ce<tensionsD ) >!( %in!r+ d!t!

/ii 5<!mple

/ii 5<!mple
)

So, (e must:
) ) ) >e!d the he!der Interpret p!rts o' the he!der, such !s si6e o' the im!ge .ind !nd re!d im!ge d!t!, !nd !ssem%le !ccording to he!der

/ot !ll 'orm!ts (ill %e so (ell documented


) Gener!ll+, ! 'ile (ill "ust %e one structure or one /$ dimension!l m!tri< !nd (ill %e e!sier to interpret

/ii 5<!mple
)

/ii 1e!der:
struct &e+(ord 'ollo(ed %+ ! list o' d!t!

t+pes !nd their n!mes

7!t! .orm!ts
)

>e!ding ! %in!r+ 'ile


fid = fopen(filename, permission_tmode, machineformat)

) .ilen!me is ! string, n!me o' +our d!t! 'ile ) Permission !lso ! string, !nd should %e CrD 'or re!ding ?de'!ults in %in!r+ modeA ) *!chine'orm!t is critic!l: re'ers to Big 5ndi!n or Oittle 5ndi!n
) C%D 'or Big, ClD 'or Oittle

7!t! .orm!ts
)

5ndi!nness
) >e'ers to (hether digits get %ig O$P> or >$PO ) .or %in!r+ string 0;0;:
) Oittle 5ndi!n: R0 ; 0 ;S 8 2TR0 ; 2 BSD G ;0 ) Big 5ndi!n: R0 ; 0 ;S 8 2TRB 2 ; 0SD G H

) P9Ds !re t+pic!ll+ O5, *!cs m!+ %e B5 ) *!&e sure to speci'+ !ccording to +our d!t!, other(ise it m!+ %e (rong0
) 5!s+ to tr+ %oth (!+s in de%ugging

7!t! .orm!ts
)

We h!#e opened ! C'ilestre!m,D no( (e c!n re!d e!ch d!t! item into ! structure 'ield
Fread, fscanf, etc

9 s+nt!< is di''erent th!n * s+nt!<


) int, ch!r, single, etc E loo& up their eUui#!lents in help 'or 're!d

/ii 5<!mple
)

.or inst!nce,
) Oo!dVni'tiVhdr 'rom .reesur'er !n!l+sis p!c&!ge, posted online
/otice the use o' !rr!+s

7!t! .orm!ts
)

4ip :;
) 3sing ! comm!nd li&e fread m!+ return ! dou%le, e#en i' +ou h!#e re!d !n integer or ch!r ) Wou c!n Ct+pec!stD %+ c!lling char(readData), etc

7!t! .orm!ts
)

4ip :2
) A d!t! item m!+ %e !nother structure. 4his (ill pro%!%l+ !lso %e de'ined in the s!me .h 'ile
) In ni'ti;.h, the nii he!der is 'ollo(ed %+ t(o structures:

7!t! .orm!ts
)

>eiter!tion:

) A structure in 9 is "ust the collection o' n!ti#e d!t! #!ri!%les (ritten to dis&, in the order the+ !re de'ined ) Wou do not re!d the structure 'rom the 'ile, %ut cre!te !n identic!l structure in m!tl!% %+ !ssem%ling e!ch d!t! item ) 4here m!+ %e no C%in!r+ sp!ceD %et(een rele#!nt d!t! items E e#er+ %it o' the 'ile gets m!pped into one o' the d!t! 'ields

7!t! .orm!ts
)

/otes on 9 s+nt!<
) Arr!+s !re decl!red %+ si6e, (ith RS ) 4he C8D me!ns ! pointer
) 4his m!+ %e useless, or the 'ile m!+ cont!in the dere'erenced d!t! ) 1ere, ed!t! is !ctu!ll+ stored !s ! ch!r!cter !rr!+ o' si6e esi6e, so (e c!n re!d it ?this is ! common (!+ to store strings in 9A

7!t! .orm!ts
)

4ip :B
) I' +ou donDt need e#er+ d!t! item, +ou c!n use fseek to "ump to the loc!tion +ou need
) When +ou re!d, +our loc!tion in the 'ile progresses 'rom the %eginning o' the #!ri!%le to the end ) Wou tr!#el count8n%+tes per re!d, n%+tes G X 'or int, ; 'or intY, Y 'or dou%le, etc ?see 're!dA

7!t! .orm!ts
)

4ip :B
) 5<!mple positions:
0 XG0QX ;X G X Q ;08; B2 G ;X Q ;Y8; BM G B2 Q ;8X BY G BM Q ;82 B9 G BY Q ;8;

7!t! .orm!ts
)

4ip :X
) Writing ! 'ile is "ust the opposite: '(rite ) @ust (rite out, in order, !ll the rele#!nt 'ields !nd +our progr!m (ill %e !%le to open the 'ile

4ip :H
) Write ! cl!ss00

Inter!ction
)

7!t! 'ile p!ssing is good, %ut sometimes (e (!nt interactivity %et(een !pplic!tions C5<tern!l Inter'!cesD in help
) See loadlibrary

) 7OODs: code li%r!ries (ritten in 9 to control h!rd(!re, etc, c!n o'ten %e c!lled in *!tl!% ) 9ustom 9 @!#! code to inter!ct (ith Z ) 92* !nd Acti#eZ: Windo(s n!ti#e communic!tion protocol

Inter!ction
)

Acti#e Z
) Allo(s progr!ms to control other progr!ms in Windo(s ) 9lient: c!lling progr!m ) Ser#er: progr!m st!rted to run ! speci'ic t!s& ?sl!#eA

Inter!ction
)

Acti#e Z
) *A/W e<!mples
) 5!ch progr!m (or&s di''erentl+, h!#e to re!d docs to use correctl+ ) *ost e<tensi#el+ used !re *S progr!ms li&e 5<cel, Word, PP4

Acti#eZ 5<!mple
)

*!tl!% Autom!tion Ser#er


) 2nd lecture ) Ie,
for i = 1:ncores h i! = actxser"er(#matlab$application#) h i!$%xecute(#t = timer(##&imerFcn##, ##batchData($$$)##)' start(t)#)'

NB: double ', not

Acti#eZ 5<!mple
)

Po(erPoint Slide Gener!tor


) Posted online

Acti#eZ 5<!mple
)

Po(erPoint Slide Gener!tor


ppt = actxser"er(#(o)er(oint$*pplication#)' ppt$*cti"ate()'

) 9re!tes ppt, ! 92* o%"ect, !nd uses it to l!unch Po(erPoint ) 4hen, does ! lot o' '!nc+ stu'' E see online 'or det!ils

92* 2%"ects
)

Wor&ing (ith 92*

S+m%ol 'or Co%"ect,D !nd here is p!ssed %+ re'erence

2%"ect t+pe

92* 2%"ects
)

Wor&ing (ith 92*


) Ser#er !pplic!tion m!+ h!#e help on 92* us!ge, %ut m!+ not ) 3su!ll+ h!#e to pl!+ h!c& tr+, %ut this isnDt too h!rd

92* 2%"ects
)

Wor&ing (ith 92*


) Ag!in, li&e (ith !n+ o%"ect, (e c!n:
fields(ob+) methods(ob+) methods"ie)(ob+)

) Bec!use these o%"ects !re designed 'or e<tern!l use, the methods !re e!s+ to underst!nd !nd use

92* 2%"ects

%xecute(handle, strin,)

Is the s!me !s

h$%xecute(strin,)

92* 2%"ects
)

Wor&ing (ith 92*


) 7ot not!tion ?!lso (ith @!#! o%"ectsA
*cti"ate(ob+) is the s!me !s ob+$*cti"ate()

) Philosophic!ll+ %etter
)

>epresents o%"ect doing something, or ! method speci'ic to !n o%"ect

) Will onl+ use dot not!tion (hen (e (rite @!#! 9 ?*!tl!% is the odd%!llA

.rid!+
)

@!#!l!%
) 5<tending *!tl!%, 'or po(er !nd speed ) /!ti#e use !nd disuse

Das könnte Ihnen auch gefallen