cs matlab review guide

101
!"#$% '() *+ ,-., /01)($"21#(03 45% 674879 *(::;0$ /01%)';2% 674879 #< =;<#2;>>? @"<1 ; )%;>>? 2(:A>#2;1%$ A)(B);: 15;1 '"021#(0< ;< ;0 % C1)%:%>? A(D%)'"> 2;>2">;1()E 7< <"25F #1 2;0 A%)'(): 1;<G< 15;0 :(<1 2;>2">;1()< 2;00(1F "<";>>? #0 ');21#(0< (' ; <%2(0$E H(D%I%)F >#G% ;>> 2(:A"1%) A)(B);:<F 674879 #< #02)%$#=>? <1"A#$ ;0$ #< (0>? %I%) ;< "<%'"> ;< ?(") 2($#0B 2;A;=#>#1? ;>>(D< #1 1( =%E J%I%) "0$%)%<1#:;1% 5(D #))#1;1#0B>? A#2G? 674879 2;0 =% ;=("1 <:;>> <%21#(0< (' 2($%E 45% A)(B);::%)< $%<#B0%$ <(:% '"021#(0< 1( =% '>%C#=>% D#15 #0A"1 I;>"%<F ="1 '() 15% most part they didn’t bother making it user K')#%0$>?E /1 #< 0(1 0%2%<<;)? 1( ;21";>>? A")25;<% 15% 674879 <('1D;)% 1( 2(:A>%1% 15#< 2(")<%F ;>15("B5 #1 #< A)(=;=>? A)%11? "<%'">L / $( 0(1 A%)<(0;>>? (D0 15% <('1D;)%E 6;0?F 0(1 ;>>F 2(:A"1%)< #0 15% >#=);)? $( 5;I% #1E 7$$#1#(0;>>?F <(:% 2(:A"1%) B%%G< 5;I% <%1 "A ; I#)1";> $%<G1(A 2;>> *#1)#C 15;1 ;>>(D< ?(" 1( ;22%<< ?(") >#=);)? $%<G1(A ')(: ?(") >;A1(AE M0'()1"0;1%>?F 15% )%:(1% $%<G1(A B%0%);>>? )"0< I%)? <>(D>? ;0$ #< A)(0% 1( ')%%N#0B ;1 ')%O"%01 #01%)I;><E /1 ;><( >#G%< 1( B#I% ?(" 0(0<%0<#2;> >(B#0 %))() messages such as “We are sor ry. This desktop has been locked, and only you can use it.” P5%0%I%) ?(" )"0 674879 #0 15% >#=);)? () ')(: ?(ur remote desktop, it will tell you it’s “initializing” and then proceed to take an unreasonable amount of t ime to generate a pointless message ;=("1 2"<1(:#N#0B <5()12"1<E / 5;I% ?%1 1( '#0$ ; :%15($ '() A)%I%01#0B 15#<E 45% 674879 <2)%%0 #< $#I#$%$ #01( ; 0":=%) (' <%21#(0< D#15 <A%2#'#2 0;:%< ;0$ 1#1>%<E 45%<% ;) % #:A()1;01 1( >%;)0 =%2;"<% 15%? :;G% "A ; >;)B% A;)1 (' 15% 1%):#0(>(B? "<%$ #0 15% 2(")<%E !"# %&''()* +,)*&-. This is the large and obvious block in the middle of your scree n labeled “Command Window.” It can be used to run individual lines of code o r display the progress of a script. Although you’d imagine it :"<1 A>;? ; I%)? #:A()1;01 )(>% #0 D) #1#0B 2($%<F #1 #< ;21";>>? A)%11? :"25 "<%>%<<E /' ?( " "<% 15% 2(::;0$ D#0$(D 1( )"0 :">1#A>% >#0%< (' 2($% <%O"%01#;>>? ;0$ )%;>#N% ?(" :;$% ; :#<1;G% <(:%D5%)%F ?(" 5;I% 1( )%$( 1 5% PHQ8R A)(2%<<E 45% 2(::;0$ D#0$(D D#>> 0(1 ;>>(D ?(" 1( %$#1 ;0?15#0B A)%I#("<>? %01%)%$F ;0$ (02% ; I;)#;=>% #< (I%)D)#11%0 15% ()#B#0;> I;>"% 2;00(1 =% )%<1()%$E 4( %01%) ; 2(::;0$ #0 15% 2(::;0$ D#0$(DF <#:A>? 1?A% #1 #0 15% >#11>% =(C "0$%)0%;15 ;0$ A)%< %01%)E /1 #< A(<<#=>% 1( %01%) :">1#A>% >#0%< (' 2($% <"25 ;< >((A< ;0$ 2(0$#1#(0;> <1;1%:%01< "<#0B shift+enter, but I wouldn’t suggest it. S(" 2;0 "<% 15% "AK;))(D to scroll through your most rece nt commands so you don’t have to retype them. If you attempt to do something that MATLAB doesn’t like or if there is a typo in your 2(::;0$F 674879 D#>> :;G% ;0 ;00(?#0B =%%A#0B <("0$ ;0$ $#<A>;? ; )%$ %))() :%<<;B% 15;1 1%>>< ?(" D5;1 15% A)(=>%: #<E 8%;)0 1( '%;) 15% %))() :%<<;B%E 71 15% I%)? =(11(:K>%'1 A;)1 (' 15% <2)%%0 MATLAB will display statuses such as “initializing”, “busy”, or “ready.” If you accidentally run an infinite >((A () ;0 %C1)%:%>? >(0B )%2 ")<#I% '"021#(0F ?(" 2;0 2;02%> ?(") >;<1 2(::;0$ =? A)%<<#0B 21)>T2E S(" 2;0 %01%) !"! 1( 2>%;) D5;1%I%) #< #0 15% 2(::;0$ D#0$(D ;1 15% 1#:%E

Upload: pookdook

Post on 02-Jun-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 1/101

!"#$% '() *+ ,-.,

/01)($"21#(03 45% 674879 *(::;0$ /01%)';2%

674879 #< =;<#2;>>? @"<1 ; )%;>>? 2(:A>#2;1%$ A)(B);: 15;1 '"021#(0< ;< ;0 %C1)%:%>? A(D%)'">2;>2">;1()E 7< <"25F #1 2;0 A%)'(): 1;<G< 15;0 :(<1 2;>2">;1()< 2;00(1F "<";>>? #0 ');21#(0< (' ; <%2(0$EH(D%I%)F >#G% ;>> 2(:A"1%) A)(B);:<F 674879 #< #02)%$#=>? <1"A#$ ;0$ #< (0>? %I%) ;< "<%'"> ;< ?(")2($#0B 2;A;=#>#1? ;>>(D< #1 1( =%E J%I%) "0$%)%<1#:;1% 5(D #))#1;1#0B>? A#2G? 674879 2;0 =% ;=("1 <:;>><%21#(0< (' 2($%E 45% A)(B);::%)< $%<#B0%$ <(:% '"021#(0< 1( =% '>%C#=>% D#15 #0A"1 I;>"%<F ="1 '() 15%most part they didn’t bother making it user K')#%0$>?E

/1 #< 0(1 0%2%<<;)? 1( ;21";>>? A")25;<% 15% 674879 <('1D;)% 1( 2(:A>%1% 15#< 2(")<%F ;>15("B5#1 #< A)(=;=>? A)%11? "<%'">L / $( 0(1 A%)<(0;>>? (D0 15% <('1D;)%E 6;0?F 0(1 ;>>F 2(:A"1%)< #0 15% >#=);)?$( 5;I% #1E 7$$#1#(0;>>?F <(:% 2(:A"1%) B%%G< 5;I% <%1 "A ; I#)1";> $%<G1(A 2;>> *#1)#C 15;1 ;>>(D< ?(" 1(;22%<< ?(") >#=);)? $%<G1(A ')(: ?(") >;A1(AE M0'()1"0;1%>?F 15% )%:(1% $%<G1(A B%0%);>>? )"0< I%)?<>(D>? ;0$ #< A)(0% 1( ')%%N#0B ;1 ')%O"%01 #01%)I;><E /1 ;><( >#G%< 1( B#I% ?(" 0(0<%0<#2;> >(B#0 %))()messages such as “We are sorry. This desktop has been locked, and only you can use it.”

P5%0%I%) ?(" )"0 674879 #0 15% >#=);)? () ')(: ?( ur remote desktop, it will tell you it’s“initializing” and then proceed to take an unreasonable amount of time to generate a pointless message;=("1 2"<1(:#N#0B <5()12"1<E / 5;I% ?%1 1( '#0$ ; :%15($ '() A)%I%01#0B 15#<E 45% 674879 <2)%%0 #<$#I#$%$ #01( ; 0":=%) (' <%21#(0< D#15 <A%2#'#2 0;:%< ;0$ 1#1>%<E 45%<% ;)% #:A()1;01 1( >%;)0 =%2;"<%15%? :;G% "A ; >;)B% A;)1 (' 15% 1%):#0(>(B? "<%$ #0 15% 2(")<%E

!"# %&''()* +,)*&-.

This is the large and obvious block in the middle of your screen labeled “Command Window.” Itcan be used to run individual lines of code or display the progress of a script. Although you’d imagine it:"<1 A>;? ; I%)? #:A()1;01 )(>% #0 D)#1#0B 2($%<F #1 #< ;21";>>? A)%11? :"25 "<%>%<<E /' ?(" "<% 15%2(::;0$ D#0$(D 1( )"0 :">1#A>% >#0%< (' 2($% <%O"%01#;>>? ;0$ )%;>#N% ?(" :;$% ; :#<1;G%<(:%D5%)%F ?(" 5;I% 1( )%$( 15% PHQ8R A)(2%<<E 45% 2(::;0$ D#0$(D D#>> 0(1 ;>>(D ?(" 1( %$#1;0?15#0B A)%I#("<>? %01%)%$F ;0$ (02% ; I;)#;=>% #< (I%)D)#11%0 15% ()#B#0;> I;>"% 2;00(1 =% )%<1()%$E

4( %01%) ; 2(::;0$ #0 15% 2(::;0$ D#0$(DF <#:A>? 1?A% #1 #0 15% >#11>% =(C "0$%)0%;15 ;0$A)%< %01%)E /1 #< A(<<#=>% 1( %01%) :">1#A>% >#0%< (' 2($% <"25 ;< >((A< ;0$ 2(0$#1#(0;> <1;1%:%01< "<#0Bshift+enter, but I wouldn’t suggest it.

S(" 2;0 "<% 15% "AK;))(D to scroll through your most recent commands so you don’t have toretype them. If you attempt to do something that MATLAB doesn’t like or if there is a typo in your2(::;0$F 674879 D#>> :;G% ;0 ;00(?#0B =%%A#0B <("0$ ;0$ $#<A>;? ; )%$ %))() :%<<;B% 15;1 1%>>< ?("D5;1 15% A)(=>%: #<E 8%;)0 1( '%;) 15% %))() :%<<;B%E 71 15% I%)? =(11(:K>%'1 A;)1 (' 15% <2)%%0MATLAB will display statuses such as “initializing”, “busy”, or “ready.” If you accidentally run an infinite>((A () ;0 %C1)%:%>? >(0B )%2")<#I% '"021#(0F ?(" 2;0 2;02%> ?(") >;<1 2(::;0$ =? A)%<<#0B 21)>T2E S("2;0 %01%)!"! 1( 2>%;) D5;1%I%) #< #0 15% 2(::;0$ D#0$(D ;1 15% 1#:%E

Page 2: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 2/101

!"# +&/012(3#.

This is the little box off to the right labeled “Workspace.” Its purpose is to keep track of all theI;)#;=>%< ;0$ $;1; 1?A%< ?(" ;)% "<#0BE 70?1#:% ?(" <;I% ; I;>"% 1( ; A;)1#2">;) I;)#;=>% () %01%) ;0?;<<#B0:%01 <1;1%:%01F 15% D()G<A;2% #< ;"1(:;1#2;>>? "A$;1%$ D#15 15% 0%D #0'():;1#(0E /1 $#<A>;?<=(15 15% 0;:% (' 15% I;)#;=>% ;0$ #1< $;1; 1?A% U; =)#%' $%<2)#A1#(0 (' $;1; 1?A%< D#>> =% B#I%0 #0 <%21#(0(0%VE /' 15% D()G<A;2% #< =%2(:#0B 1(( 2>"11%)%$ D#15 "<%>%<< I;)#;=>%<F ?(" 2;0 )%<%1 #1 =? %01%)#0B!"#$% #0 15% 2(::;0$ D#0$(DE

%&''()* 4,15&/6.

45#< >#11>% =(C G%%A< 1);2G (' ;>> 15% 2(::;0$< ?(" 5;I% %01%)%$ <#02% 15% =%B#00#0B (' 15%674879 <%<<#(0E /' ?(" ;22#$%01;>>? 2>%;) 15% 2(::;0$ D#0$(D ;0$ D()G<A;2% ="1 <1#>> 0%%$ 15%#0'():;1#(0 ')(: 15%:F ?(" 2;0 ;22%<< #1 ')(: 2(::;0$ 5#<1()?E Q15%)D#<%F ?(" <5(">$ @"<1 A)%1%0$ #1doesn’t exist.

!"# %7//#)5 8,/#35&/6.

This box is labeled “Current Folder” and is slightly confusing to become accustomed to. MATLAB2;0 (0>? ;22%<< '#>%< ;0$ A)(B);:< 15;1 )%<#$% #0 ?(") 2"))%01 $#)%21()?L #' ?(" ;11%:A1 1( )"0 ; '"021#(0() <2)#A1 ')(: ; $#''%)%01 '(>$%)F 674879 D ill give you an error message saying that it doesn’t exist. ItD(">$ 15%)%'()% =%5((I% ?(" 1( 2)%;1% ;0 ()B;0#N%$ <%1 (' '(>$%)< ;0$ <"=K'(>$%)< '() *+ ,-.,F D#15%;25 5(:%D()G ;<<#B0:%01 5;I#0B #1< (D0 '(>$%)E /' ?(" 0%%$ 1( ;22%<< ; '"021#(0 ')(: ;0(15%)5(:%D()GF D5#25 D#>> #0%I#1;=>? 5;AA%0 '() <(:% (' 15% :()% $#''#2">1 A)(=>%:<F <#:A>? 2(A?WA;<1% #1into the current directory’s folder and submit it with your homework problems.

4( 25;0B% 15% 2"))%01 $#)%21()?F >(2;1% 15% ="11(0 (0 15% A)#:;)? 1((>=;) ;1 15% 1(A (' 15%<2)%%0 ;0$ 1( 15% )#B51 (' 15% 2"))%01 '(>$%) $#<A>;?E /1 <5(">$ >((G >#G% ;0 %>>#A<#<E 45%0 @"<1 0;I#B;1% the folder you wish to select and click “OK.” I suggest saving your entire CS 1371 folder on your GT Prism$)#I% <( ?(" 2;0 ;22%<< #1 ')(: ;0? 2(:A"1%) (0 2;:A"<E

Page 3: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 3/101

+%21#(0 Q0%3 +2)#A1< ;0$ 15% 7<<#B0:%01 QA%);1()

/ D#>> =% D)#1#0B 15%<% <%21#(0< D#15 15% A)#:;)? '(2"< (' ;<<#<1#0B #0 2(02%A1< "<%$ 1( 2(:A>%1%5(:%D()G ;<<#B0:%01<F ="1 ;>> (' 15% =;<#2 #0'():;1#(0 #< "<%'"> (0 15% 1%<1<E

!"# 911,:)'#)5 ;2#/(5&/.

70? >#0% (' 2($% 15;1 "<%< ; <#0B>% %O";>< <#B0 U15% ;<<#B0:%01 (A%);1()V #< 2;>>%$ ;0 ;<<#B0:%01<1;1%:%01E 7<<#B0:%01 #< "<%$ A)#:;)#>? 1( <%1 I;>"%< 1( I;)#;=>%< ;0$ D()G< 15% <;:% D;? D#15 ;0?$;1; 1?A%E 7>> I;)#;=>% 0;:%< ;)% 2;<%Ksensitive, so “a” and “A” can be used as separate variables. BeI%)? 2;)%'"> D5%0 0;:#0B ;0$ ;22%<<#0B I;)#;=>%<E X;)#;=>% 0;:%< ;)% B%0%);>>? <5()1 %0("B5 1( 1;G% "A>#11>% <A;2% ="1 >(0B %0("B5 1( =% %;<#>? $#<1#0B"#<5%$E 45% >;<1 15#0B ?(" D;01 1( $( #< 5;I% 1( '#C ?(")code when you can’t even figure out what it does.

45%)% ;)% 15)%% #:A()1;01 )%<1)#21#(0< (0 0;:#0B I;)#;=>%<3

,E

A variable’s name must begin with an uppercase or lowercase letter. The rest of the name may2(01;#0 ;0? 2(:=#0;1#(0 (' >%11%)< ;0$ 0":=%)<EYE A variable’s name cannot contain spaces. Obviously, MATLAB would then be unable to

$#<1#0B"#<5 =%1D%%0 15% I;)#;=>% ;0$ 15% <"))("0$#0B 2($%E-E A variable’s name cannot contain any special characters except underscores. ZE 7 I;)#;=>% <5(">$ 0%I%) =% B#I%0 15% <;:% 0;:% ;< ; ="#>1K#0 674879 '"021#(0 U:#0F :;CF

<()1F%12EV

9? 15%<% )">%<F 15% '(>>(D#0B D(">$ =% >%B;> I;)#;=>% 0;:%<3 7 F ; F ;, F ;,; F ;[;45% '(>>(D#0B ;)% 15%)%'()% #>>%B;> I;)#;=>% 0;:%<3 , F ,; F ;3 F 3 F ; ,F ;\

Assignment statements take the form A = B, where “A” is a variable or collection and “B” is an

expression that can be immediately evaluated. MATLAB first evaluates “B” then sets “A” equal to it.7<<#B0:%01 <1;1%:%01< $( JQ4 %<1;=>#<5 )%>;1#(0<5#A< =%1D%%0 I;)#;=>%<L 15%? 2;0 (0>? =% "<%$ 1( <%1 ;I;)#;=>% %O";> 1( ; G0(D0 I;>"%E Q02% ;B;#0F 25;0B#0B 15% I;>"%< (' (15%) I;)#;=>%< "<%$ #0 ;0;<<#B0:%01 <1;1%:%01 5;< 0( %''%21 (0 15% A)%I#("<>? ("1A"11%$ I;)#;=>%E

If no “A” is inputted, the value of “B” will automatically be stored in MATLAB’s temporaryvariable “ans.” “ans” can be accessed at any time and is always placed in the workspace, but each new0(0K<A%2#'#2 ;<<#B0:%01 <1;1%:%01 (I%)D)#1%< D5;1%I%) #< <1()%$ #0 #1E /1 #< B%0%);>>? ; =;$ #$%; 1( )%>?on “ans” to store any values you may be using later.

9? $%';">1F 15% )%<">1 (' ;0 ;<<#B0:%01 <1;1%:%01 #< #::%$#;1%>? $#<A>;?%$ (0 15% 2(::;0$D#0$(DE H(D%I%)F 15#< 2;0 =%2(:% I%)? #))#1;1#0B D5%0 ?(" )"0 >(0B <2)#A1< () 25;0B% >;)B% 2(>>%21#(0<

(' I;>"%<L 15% 2(::;0$ D#0$(D D#>> O"#2G>? =%2(:% 2>(BB%$ D#15 "<%>%<< #0'():;1#(0 15;1 <>(D< 15%execution of your code. To prevent this, you can “suppress” the output of individual lines of code by%0$#0B 15%: D#15 ; <%:#2(>(0E 45% )%<">1 (' ; <"AA)%<<%$ ("1A"1 #< <1#>> <1()%$ #0 15% D()G<A;2% ="1 D#>>0(1 =% $#<A>;?%$ #0 15% 2(::;0$ D#0$(DE P#15 A);21#2%F ?(" D#>> >%;)0 1( <"=2(0<2#("<>? <"AA)%<< ;>>("1A"1< ;< ?(" D)#1%E 674879 D#>> ;"1(:;1#2;>>? 0(1#'? ?(" (' "0<"AA)%<<%$ ("1A"1< =? $#<2(>()#0B 15%equal’s <#B0E

Page 4: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 4/101

P5%0%I%) 674879 %02("01%)< <A;2%<F #1 ;"1(:;1#2;>>? #B0()%< 15%:E S(" 2;0 15%)%'()% ;$$<A;2%< #0 >#0%< (' 2($% 1( :;G% 15%: :()% >%B#=>%E

<1,): 5"# 8&5 -,5" =(1,3 9/,5"'#5,3.

45% 674879 0(1;1#(0 1( ;$$F <"=1);21F :">1#A>?F $#I#$%F () );#<% 1( ; A(D%) #< %C;21>? D5;1 ?("

D(">$ %CA%21 UTF KF ]F WF ^VE H(D%I%)F 674879 :"<1 5;I% ; D;? (' $#<1#0B"#<5#0B =%1D%%0 )%B">;);)#15:%1#2 ;0$ <A%2#;> :;1)#C (A%);1#(0<E _() #0<1;02%F ?(" 2;0 %#15%) :">1#A>? %;25 %>%:%01 #0 (0%:;1)#C =? 15% 2())%<A(0$#0B %>%:%01 #0 ;0(15%) () ;21";>>? A%)'(): :;1)#C :">1#A>#2;1#(0 "<#0B >#0%;);>B%=);E J(1%3 674879 "<%< $%2#:;>< #0<1%;$ (' ');21#(0< D5%0%I%) #1 %02("01%)< ; 0(0K#01%B%)E

4( $#''%)%01#;1% =%1D%%0 15% 1D(F 674879 "1#>#N%< ; $(1 UEV <?<1%: D#15 15% <?:=(>< ]F WF ;0$ ^E4( A%)'(): %>%:%01 =? %>%:%01 :">1#A>#2;1#(0F $#I#<#(0F () %CA(0%01#;1#(0F <#:A>? ;$$ ; <#0B>% A%)#($=%'()% 15% ;)#15:%1#2 <?:=(> UE]F EWF () E^VE 8#0%;) ;>B%=); '"021#(0< ;)% A%)'():%$ D5%0%I%) 15% $(1 #<;=<%01 ;0$ D#>> 2;"<% %))()< #' 15% $#:%0<#(0< (' 15% :;1)#2%< $( 0(1 :;125 A)(A%)>?E J(1% 15;1 15% $(15;< 0( %''%21 (0 <2;>;) I;>"%< U`]` #< 15% <;:% ;< `E]`VE

>3/,251.

7< A)%I#("<>? <1;1%$F "<#0B 15% 2(::;0$ D#0$(D 1( <(>I% 2(:A>%C A)(=>%:< #< #0;$I#<;=>%=%2;"<% #1 $(%< 0(1 ;>>(D ?(" 1( %$#1 2(::;0$< ?(" 5;I% ;>)%;$? )"0E *(0<%O"%01>?F :(<1 2($#0B #<2(:A>%1%$ "<#0B <2)#A1< ;0$ 15% 674879 '"021#(0 %$#1()E 7 <2)#A1 #< ; =>;0G <A;2% '() #0A"11#0B =>(2G< ('2($% () '"021#(0<E P5%0 ?(" '#0#<5 D)#1#0B ; <2)#A1F ?(" 2;0 )"0 15% %01#)% 15#0B ;1 (02%L #' ;0 %))()occurs, you can edit and rerun your code to your heart’s content.

4( (A%0 ; 0%D <2)#A1F 2>#2G 15% #2(0 #0 15% "AA%)K>%'1 2()0%) 15;1 >((G< >#G% ; =>;0G <5%%1 (' A;A() A)%<< 21)>T0E P5%0 ?(" '#0#<5 1?A#0B ("1 ?(") 2($%F ?(" 2;0 )"0 15% <2)#A1 =? "<#0B 15% B)%%0 1)#;0B>%#2(0 () =? A)%<<#0B _`E 4( <;I%F B( 1( '#>% save as… or press ctrl+s. Scripts are automatically saved as .m

'#>%<F 15% $%';">1 '#>% 1?A% '() 674879E 7>D;?< >%;I% 15% '#>% 1?A% ;< E: #' D;01 1( )%2%#I% 2)%$#1E

/' 674879 $#<>#Ges something you’ve written on a script, it will inform you by enclosing aI;)#;=>% #0<#$% ; $#<2(>()%$ =(C () =? "0$%)>#0#0B A;)1 (' ?(") 2($% #0 )%$E 45#< #< ; I%)? O"#2G D;? 1(spot typos, but don’t rely on it for everything.

/' ?(" A>;0 1( 1%<1 ?(") <2)#A1 ')%O"%01>?F ?(" 2;0 $(2G 15% <2)#A1 %$#1() #0<#$% 15% 2(::;0$D#0$(DE 45#< D#>> ;>>(D ?(" 1( I#%D 15% I;>"%< (' $#''%)%01 I;)#;=>%< ')(: 15% D()G<A;2% D#15("1 5;I#0B1( :#0#:#N% 15% <2)#A1E 4( $(2G 15% %$#1()F 2>#2G 15% <:;>> ;))(D (0 15% >%'1 @"<1 "0$%) 15% :#0#:#N%="11(0E 45% %$#1() 2;0 =% "0$(2G%$ #0 15% <;:% D;? =? 2>#2G#0B 15% "AK;))(D ;=(I% 15% :#0#:#N%="11(0E

/' ?(" D#<5 1( )"0 ; <2)#A1 (0% >#0% ;1 ; 1#:% );15%) 15;0 ;>> ;1 (02%F ?(" 2;0 %01%) $%="B :($%=? 2>#2G#0B 15% B);? <A;2% 1( 15% )#B51 (' 15% >#0% 0":=%)< (0 15% >%'1 <#$% (' 15% <2)%%0E 7 )%$ 2#)2>% D;AA%;) (0 15% $%="BB%$ >#0%E 70? 0":=%) (' >#0%< 2;0 =% $%="BB%$E P5%0 )"0F 15% <2)#A1 D#>>#::%$#;1%>? A)(2%%$ ;>> 15% D;? 1( 15% '#)<1 $%="BB%$ >#0%F 15%0 <1(AE S(" 2;0 15%0 2(01#0"% )"00#0B%;25 #0$#I#$";> >#0% =? A)%<<#0B 15% #2(0 D#15 15% 2")I? =>"% ;))(D (0 1(A (' ; <5%%1 (' A;A%) >;=%>%$“step.” The “step in” icon allows you debug any internal functions that your script runs. “Continue”;>>(D< 15% 2($% 1( )"0 0():;>>? "01#> #1 )%;25%< 15% 0%C1 $%="BB%$ >#0%E P5#>% #0 $%="B :($%F ?(" 2;0$#<A>;? 15% I;>"%< (' ;0? I;)#;=>%< =? 5(I%)#0B 15% :("<% (I%) 15%: () =? <#:A>? I#%D#0B 15%#) A)(B)%<<

Page 5: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 5/101

#0 15% D()G<A;2%E /' ?(" 2;00(1 >(2;1% 15% <(")2% (' ;0 %))()F $%="BB#0B ?(") <2)#A1 #< ;0 %C2%>>%01 D;?1( 1);2G 15% A)(=>%:E

S(" 2;0 ;$$ ?(") (D0 A%)<(0;> 2(::%01< 1( ;0? (' ?(") 2($% 1( :;G% #1 %;<#%) '() ?(" () (15%)people to understand. Simply precede any comments with a “%” percentage sign. MATLAB completely#B0()%< ;0? B)%%0 1%C1 '(>>(D#0B ; A%)2%01;B% <#B0 D5%0 #1 %C%2"1%< 2($%E 4( <%% ;0 %C;:A>%F @"<1 >;1 ; 5DE: '#>%E 4( 2(::%01 ; >#0% (' 2($%F 2>#2G (0 #1 ;0$ A)%<< 21)>T)E 4( "02(::%01 <(:%15#0BF A)%<<21)>T1E /1 #< 0(1 0%2%<<;)? 1( ;21";>>? 5#B5>#B51 15% 2($% ?(" <#B5 1( 2(::%01 () "02(::%01E S(" 2;0%;)0 %C1); 2)%$#1 A(#01< (0 ?(") 5(:%D()G ;<<#B0:%01< =? 2(::%01#0B ?(") 2($%E

=7,?5@A) B9!C9= D7)35,&)1.

45% $%<#B0%)< (' 674879 #02>"$%$ 5"0$)%$< (' ="#>1K#0 '"021#(0< 1( ;<<#<1 "<%)< #0 D)#1#0B 2($%E45%<% '"021#(0< ;>>(D ?(" 1( A%)'(): (15%)D#<% 2(:A>%C 1;<G< #0 ; <#0B>% >#0% (' 2($%E 4( 2;>> ; '"021#(0F1?A% #1< 0;:% '(>>(D%$ =? ;0? #0A"1< #0 A;)%015%<%<F <%A;);1%$ =? 2(::;<E / D#>> >#<1 ;0? "<%'">'"021#(0< ;< D%>> ;< =)#%' $%<2)#A1#(0< (' 15%: #0 %;25 <%21#(0 (' 15#< B"#$%E

/' ?(" D#<5 1( A%)'(): ; )%>;1#I%>? 2(::(0 1;<G ;0$ ;)% D(0$%)#0B D5%15%) 674879 5;< ;="#>1K#0 '"021#(0F #1 A)(=;=>? $(%<E !( 1( H%>A'"021#(0 =)(D<%) U<5#'1T_,V ;0$ <%;)25 '() 15% 0;:% ('15% '"021#(0 ?(" ;)% >((G#0B '()E _"021#(0 0;:%< ;)% B%0%);>>? #02)%$#=>? (=I#("<F %C;21>? D5;1 ?("D(">$ %CA%21 15%: 1( =%E _"021#(0 0;:%< ;)% ;><( 2;<%K<%0<#1#I%E

<#0UV *;>2">;1%< 15% <#0%2(<UV *;>2">;1%< 15% 2(<#0%<O)1UV *;>2">;1% 15% <O";)% )((1;=<UV *;>2">;1%< 15% ;=<(>"1% I;>"%%CAUV *;>2">;1% %C

EF('2?#1.

/0A"13 Q"1A"1 1( *(::;0$ P#0$(D3! #$% & !' & ! ' & !' & !(

/0A"13 Q"1A"1 1( *(::;0$ P#0$(D3' & ! ' & !) & ' ) & !' & * ' & *) ) & !J(1% 15;1 25;0B#0B 15% I;>"% (' C 5;$ 0( %''%21 (0 ?E) & + ,--.-( /$0123$10 4#-3#561 +a%:%:=%) 15;1 I;)#;=>% 0;:%< ;)% 2;<%K<%0<#1#I%E' & ' 7 8 ' & 9

:-3;1 # %<-3=; ;>#; ?366 <#6</6#;1 ;>1 -#03/% #$0 %/-2#<1 #-1# .2 # %=>1-1@341$ # 4.6/A1 .2 8!B

Page 6: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 6/101

4.6/A1 & 8!C-#03/% & D4.6/A1BEFBGHBG=3IBJD8BGFIC%/-2#<1K#-1# & HBE=3BE-#03/%BJLC(The constant π is expressed as “pi” );15%) 15;0 D#15 <?:=(><V

:-3;1 # %<-3=; ;>#; /%1% ;>1 63$1#- -16#;3.$%>3= 51;?11$ ;>1 =.3$;% DFMHI #$0DNLM!I ;. 23$0 ;>1 )N4#6/1 2.- ' & LOB

'8 & FC)8 & HC'L & NLC)L & !C%6.=1 & D)L – )8I BG D'L – '8IC)K3$; & )8 – %6.=1 BE '8C)F & LO BE %6.=1 7 )K3$;C

!& %&'2?#5# 4&'#-&/0 911,:)'#)51.

,E *)%;1% ; '(>$%) #0 ?(") *+ ,-., '(>$%) '() 15% 5(:%D()G ;<<#B0:%01E 6;G% #1 %;<? 1( '#0$EYE !( 1( 4K+O";)% 7<<#B0:%01< ;0$ 2>#2G (0 15% 5(:%D()G ;<<#B0:%01E-E Save each of the files under “Additional resources for this assignment” by right K2>#2G#0B ;0$

selecting “save target as…”. ZE QA%0 674879 ;0$ 25;0B% 15% $#)%21()? 1( 15% <A%2#'#2 5(:%D()G '(>$%)E`E QA%0 15% 79*<E: '#>% ;0$ '(>>(D 15% $#)%21#(0<E P5%0 ?(" ;)% '#0#<5%$F ?(" 2;0 25%2G ?(")

;0<D%)< =? )"00#0B 15% 79*< A)%test file. Right click the pretest in the directory and select “Run

File.” The pretest will display which answers are correct or incorrect on the command window. bE QA%0 15% 5DE: '#>% ;0$ D)#1% ?(") A%)<(0;> #0'():;1#(0 ;1 15% 1(AE 45% $%<2)#A1#(0< '() 15% $)#>>A)(=>%:< D#>> #02>"$% ;>> #0A"1<F ("1A"1<F ;0$ 25;);21%) 2>;<<%<E 7>D;?< )%:%:=%) 1( 25%2G 15%character class of your outputs. Don’t forget to comment your code.

.E *)%;1% ; 0%D '#>% #0 15% <2)#A1 %$#1() '() %;25 $)#>> A)(=>%:E P5%0 ?(" '#0#<5F 1%<1 15%:15()("B5>?E /' 15%)% ;)% 1%<1 2;<%< (0 15% 5DE: '#>%F ?(" 2;0 "02(::%01 15%: ;0$ )"0 15% 5D'#>% ;< >(0B ;< ?(") <2)#A1< ;)% <;I%$ #0 15% <;:% $#)%21()?E 7>1%)0;1#I%>?F ?(" 2;0 2(A? 15% 1%<12;<%< ;0$ )"0 15%: ')(: 15% 2(::;0$ D#0$(DE

cE 7'1%) ?(" 2(:A>%1% 15% $)#>> A)(=>%:<F "A$;1% 15% #0'():;1#(0 )%B;)$#0B 2(>>;=();1#(0 (0 15%5DE: '#>%E J;I#B;1% =;2G 1( 15% <;:% ;<<#B0:%01 A;B% (0 4K<O";)% ;0$ <"=:#1 ;>> '#>%< >#<1%$ #0the “Files to submit” list.

dE S(" 2;0 <"=:#1 ;< :;0? 1#:%< ;< ?(" D;01 =%'()% 15% $%;$>#0% ;0$ D#>> ')%O"%01>? 5;I%(AA()1"0#1#%< 1( )%<"=:#1 ;'1%) ?(" )%2%#I% ?(") B);$%E a%<"=:#<<#(0< ;)% B);$%$ ;< 15%;I%);B% (' 15% 1D( <"=:#<<#(0< %C2%A1 (0 1%<1 D%%G<E

H(:%D()G ;<<#B0:%01< ;)% B);$%$ ;"1(:;1#2;>>? =? ; 2(:A"1%)E /1 D#>> 1%<1 %;25 (' ?(") <2)#A1<() '"021#(0< :">1#A>% 1#:%< D#15 I;)#("< #0A"1< $%1%):#0%$ =? 15% 47<E 45%? D#>> "<% ;0? :%;0< A(<<#=>%1( :;G% ?(") 2($% )"0 ;0 %))() ;0$ 2;"<% ?(" 1( B%1 ; N%)( (0 15% A)(=>%:E _() 15#< )%;<(0F ?(" <5(">$0%I%) )%>? <(>%>? (0 15% 1%<1 2;<%< A)(I#$%$ D#15 15% 5(:%D()G '#>%E 6;G% <")% ?(") '"021#(0< 2;0 $%;>

Page 7: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 7/101

D#15 #0A"1< <"25 ;< 0%B;1#I% 0":=%)<F ');21#(0<F ;0$ %:A1? I%21()< () <1)#0B<E /' ?(" 2;0 '#0$ (0% ("1A"1="1 0(1 ;0(15%)F <%1 15% $#''#2">1 ("1A"1 %O";> 1( <(:%15#0B A(#01>%<< >#G% b <( ?(" 2;0 B%1 A;)1#;> 2)%$#1Ea%:%:=%)3 ;0? 2($% 15;1 )"0< ;0 %))() )%<">1< #0 ; N%)(E

Page 8: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 8/101

+%21#(0 4D(3 _"021#(0<

45% A)#:;)? $);D=;2G (' <2)#A1< #< 15%#) >;2G (' I;)#;=#>#1?L 1( )"0 ; <2)#A1 D#15 $#''%)%01 <1;)1#0BI;>"%<F ?(" :"<1 :;0";>>? 25;0B% %;25 (' 15% A)%$%1%):#0%$ I;)#;=>%<E 7$$#1#(0;>>?F :;0? A)(=>%:<

)%O"#)% )"00#0B 15% <;:% =>(2G (' 2($% :;0? 1#:%<E M<#0B '"021#(0< ;>>(D< ?(" 1( 2(:A>%1% <"25 1;<G<#0 ; :()% 2(02#<%F %;<#>? "0$%)<1;0$;=>%F '():;1E

7 '"021#(0 #< <#:A>? ; <2)#A1 D#15 I;)#;=>% #0A"1< ;0$ ("1A"1<E S(" 2;>> 15% '"021#(0 D#15D5;1%I%) #0A"1< ?(" D#<5 1( "<%F #1 $(%< <(:%15#0BF ;0$ #1 )%1")0< 15% '#0;> )%<">1 1( D5;1%I%) 2;>>%$ #1EOnce you have written a function, you don’t even have to know exactly what it do %<— @"<1 D5;1 #1 1;G%<#0 ;0$ D5;1 #1 )%B")B#1;1%<E

+/,5,): D7)35,&)1.

RC2%A1 '() ; '%D >#0%< (' 2($%F '"021#(0< ;)% ;=<(>"1%>? #$%01#2;> 1( <2)#A1<E 45% :;#0 $#''%)%02%;0$F 2(#02#$%01;>>?F 15% %;<#%<1 D;? 1( <A(1 ; '"021#(0 #< 15% '#)<1 >#0%F 15% '"021#(0 5%;$%)E 45% 5%;$%)2(01;#0< ;>> (' 15% =;<#2 #0'():;1#(0 2(02%)0#0B 15% '"021#(0 #0 15% '(>>(D#0B '():3

2/$<;3.$ P./;=/;8M ./;=/;LM ./;=/;FQ & $#A1K.2K2/$<;3.$ D3$=/;8M 3$=/;LI()2/$<;3.$ ./;=/;8 & $#A1K.2K2/$<;3.$ D3$=/;8I

When you type the word “function”, MATLAB should recognize it and color it blue. Please)%:%:=%) 15;1 <A;2%< $( 0(1 :;11%)F ="1 2(::;< $(E /0 <#1";1#(0< D#15 (0>? (0% #0A"1W("1A"1F =);2G%1<:;? =% %C2>"$%$ ="1 A;)%015%<%< ;)% ;>D;?< 0%2%<<;)?E 7 '"021#(0 2;0 5;I% ;0? 0":=%) (' #0A"1< ()outputs, even zero. You can use the same variable as both an input and an output as long as you don’t0%%$ 1( G%%A 1);2G (' #1< ()#B#0;> I;>"%E 7>15("B5 ?(" D#>> A)(=;=>? 0%I%) %02("01%) ; '"021#(0 D#15 0(#0A"1<F #1 #< O"#1% 2(::(0 '() (0% 1( 5;I% 0( ("1A"1< #' #1< A")A(<% #< <#:A>? 1( A)($"2% ; A>(1 () A)#01<(:%15#0B ("1 1( 15% 2(::;0$ D#0$(DE /' 15% '"021#(0 5;< 0( ("1A"1<F %>#:#0;1% 15% %O";>< <#B0 ;0$("1A"1<E 45"<3

2/$<;3.$ $#A1K.2K2/$<;3.$ D3$=/;8M 3$=/;LM 3$=/;FI

6(<1 '"021#(0< ;)% %0$%$ D#15 the word “end” to let MATLAB know that the function is2(:A>%1%E e(#0B <( #< (0>? 2(:A>%1%>? 0%2%<<;)? #' ?(" A>;0 (0 "<#0B 5%>A%) '"021#(0<F D5#25 / D#>> 0(D%CA>;#0E 7>15("B5 '"021#(0< ;)% 0():;>>? 2;>>%$ $#)%21>? ')(: 15% 2(::;0$ D#0$(DF 15%? 2;0 ;21";>>?2;>> (15%) '"021#(0< ;< D%>>F ;< >(0B ;< ;>> 15% '#>%< 0%%$%$ ;)% <;I%$ #0 15% 2"))%01 $#)%21()? () ;$$%$ 1(15% A;15E

/' ?(" D#<5 1( A%)'(): ; <:;>> 1;<G :">1#A>% 1#:%< #0 ; <#0B>% '"021#(0F ?(" 2;0 D)#1% ; <:;>>5%>A%) '"021#(0 1( ;<<#<1 ?("E f"<1place the helper function after the “end” of the main function. Doing<( 2;0 <;I% <A;2% ;< D%>> ;< :;G% ?(") 2($% :()% )%;$;=>%E H%)% #< ;0 %C;:A>% (' ; 5%>A%) '"021#(0E

2/$<;3.$ P./;8M ./;LQ & >16=1-,'#A=61 D#M5M<I./;8 & <.$2#$@61R/A51-D#IC./;8 & ./;8 N <.$2#$@61R/A51-D # 7 D5 N #IBJFIC./;L & <.$2#$@61R/A51-D5 7 *BE#IC

1$0

Page 9: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 9/101

Page 10: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 10/101

EF('2?#1.

Let’s just take the scripts from section one and turn them into functions. Remember to make your'"021#(0< %;<? 1( "0$%)<1;0$ =? 0;:#0B I;)#;=>%< A)(A%)>?E

2/$<;3.$ P-#03/%M %/-2#<1K#-1#Q & <3-<61S;/22 D4.6/A1I -#03/% & D4.6/A1BEFBGHBG=3IBJD8BGFIC %/-2#<1K#-1# & HBE=3BE-#03/%BJLC 1$0

2/$<;3.$ )F & 1';-#=.6#;1 D'8M 'LM )8M )LI %6.=1 & D)L – )8I BG D'L – '8IC )K3$; & )8 – %6.=1 BE '8C )F & LO BE %6.=1 7 )K3$;C 1$0

Page 11: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 11/101

+%21#(0 45)%%3 X%21()<

+( ';)F D% 5;I% (0>? 2(0<#$%)%$ <#1";1#(0< 15;1 #0I(>I% D()G#0B D#15 <#0B>% I;>"%<E H(D%I%)F D%:;? D#<5 1( (A%);1% (0 >;)B% <%1< (' 0":=%)< ;1 15% <;:% 1#:%E /0 15%<% <#1";1#(0<F D% "1#>#N% I%21()<F

>;)B% 2(>>%21#(0< (' <2;>;) O";01#1#%<E 7< ; :;11%) (' ';21F %I%0 <#0B>% 0":=%)< #0 674879 ;)% #01%)A)%1%$;< I%21()< (' >%0B15 (0%E X%21()< ;)% %;<? 1( D()G D#15 ;0$ %;<? 1( "0$%)<1;0$E

%/#(5,): G#35&/1.

4( 2)%;1% ; I%21()F <#:A>? %02>(<% ; >#<1 (' 0":=%)< () I;)#;=>%< <%A;);1%$ =? <A;2%< () 2(::;<#0 <1);#B51 =);2G%1<E X%21()< 2;0 =% (' ;0? >%0B15F %I%0 (0% () N%)(E X%21()< (' >%0B15 N%)(F () %:A1?I%21()<F ;)% "<";>>? "<%$ 1( #0#1#;>#N% I;)#;=>%< 15;1 D#>> =% '#>>%$ >;1%)E /' ?(" D;01 1( 2)%;1% ; 0%DI;)#;=>% (' ; 0(0KA)%$%1%):#0%$ >%0B15F '#)<1 #0#1#;>#N% #1 ;< ;0 %:A1? I%21()E

S(" 2;0 ;><( 2)%;1% 2(>":0 I%21()< #0 :"25 15% <;:% D;?E +#:A>? <%A;);1% ;>> %>%:%01< D#15<%:#2(>(0< 1( #0$#2;1% 15;1 15%? <5(">$ =% A>;2%$ (0 1(A (' %;25 (15%)E 674879 #0$%C%< ;0$ <>#2%<2(>":0 I%21()< #0 15% <;:% D;?E

4( 2(0I%)1 )(D I%21()< ')(: )(D 1( 2(>":0 () 2(>":0 1( )(DF 1);0<A(<% 15%: =? '(>>(D#0B15%: D#15 ;0 ;A(<1)(A5%E 45% 1);0<A(<% '"021#(0 #< 0(1 >#:#1%$ 1( 1);0<A(<#0B I%21()<L #1 ;21";>>? <D;A<15% )(D< ;0$ 2(>":0< (' ;0? (0% () 1D(K$#:%0<#(0;> 2(>>%21#(0E

41< & P8 L F H !QC41<L & P*M 9M TM UQC1A=;)V1< & PQC<.6/A$V1< & P8C LC FC HC !Q

!"# %&?&) ;2#/(5&/.

6;0? I%21()< ;)% 1(( >;)B% 1( 2)%;1% :;0";>>?E 4( B%0%);1% <%1< (' %I%0>? #02)%:%01%$0":=%)<F 674879 "<%< ; 2(>(0 (A%);1()F 0(1 1( =% 2(0'"<%$ 15% <%:#2(>(0 "<%$ 1( <"AA)%<< ("1A"1<E45% 2(>(0 (A%);1() 1;G%< #0 ; <1;)1 I;>"%F ; <1%A I;>"%F ;0$ ; '#0;> I;>"%L #1 B%0%);1%< ; I%21() ('0":=%)< );0B#0B ')(: 15% <1;)1 I;>"% 1( 15% <1(A I;>"% ;0$ #02)%:%01%$ =? 15% <1%A <#N%E RCA)%<<#(0<"<#0B 15% 2(>(0 (A%);1() $( 0(1 5;I% 1( =% %02>(<%$ #0 =);2G%1<E 7>> I%21()< ;)% (' 1?A% $("=>%E

2(>(0X%2 h <1;)13<1%A3<1(A

/' ; <1%A <#N% #< 0(1 <A%2#'#%$F 674879 D#>> "<% 15% $%';">1 <1%A (' (0%E +1%A <#N%< 2;0 =% A(<#() 0%B;1#I%E 70? (' 15% 15)%% #0A"1< 2;0 =% <"=<1#1"1%$ '() ; I;)#;=>% <1()%$ #0 15% 2"))%01 D()G<A;2%Ei"11#0B <1"A#$ %CA)%<<#(0< #01( 15% 2(>(0 (A%);1() ;>:(<1 0%I%) A)($"2%< ;0 %))()E H%)% #< ; >#<1 (')%'%)%02%< '() ;=<")$ <#1";1#(0<E

,E /' 15% <1%A <#N% #< %O";> 1( N%)(F )%B;)$>%<< (' 15% (15%) 1D( #0A"1<F A)($"2%< ;0 %:A1? I%21()EYE /' 15% <1;)1 ;0$ <1(A I;>"%< ;)% %O";>F )%1")0< ; I%21() 2(01;#0#0B (0>? 15;1 0":=%) "0>%<< 15%

<1%A I;>"% #< N%)(E

Page 12: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 12/101

-E /' 15% <1;)1 I;>"% #< >%<< 15;0 15% <1(A I;>"% ="1 15% <1%A <#N% #< 0%B;1#I%F A)($"2%< ;0 %:A1?I%21()E

ZE /' 15% <1;)1 I;>"% #< B)%;1%) 15;0 15% <1(A I;>"% ="1 15% <1%A <#N% #< A(<#1#I%F A)($"2%< ;0 %:A1?I%21()E

7>15("B5 15% <1;)1 I;>"% #< ;>D;?< #02>"$%$ #0 15% )%<">1#0B I%21()F 15% <1(A I;>"% D#>> (0>? =%#02>"$%$ #' #1 ';>>< D#15#0 15% %C;21 <1%A <#N% (' 15% I;>"% =%'()% #1E 45"<F j3Z3. A)($"2%< 15% I%21() kj ZD5#25 $(%< 0(1 #02>"$% .E S(" :"<1 ;>D;?< =% 2;)%'"> 1( <%1 15% <1%A I;>"% A)(A%)>? #' ?(" D;01 15% <1(AI;>"% 1( =% #02>"$%$E

C,)12(3# HI 3

/' ?(" ;=<(>"1%>? :"<1 #02>"$% =(15 15% <1;)1 ;0$ <1(A I;>"%< () ;)% #01%)%<1%$ #0 B%0%);1#0B ;I%21() (' ; A;)1#2">;) >%0B15F ?(" 2;0 "<% 15% >#0<A;2%UV '"021#(0E 8#0<A;2%UV 1;G%< #0 ; <1;)1 I;>"%F ; <1(AI;>"%F ;0$ 15% $%<#)%$ >%0B15 (' 15% ("1A"1 I%21() UJQ4 ; <1%A <#N%V ;0$ A)($"2%< ; I%21() (' >#0%;)>?<A;2%$ 0":=%)< =%1D%%0 15% <1;)1 ;0$ <1(A I;>"%<E 45% <1;)1 ;0$ <1(A I;>"% ;)% B";);01%%$ 1( =%#02>"$%$F ;0$ 15% <A;2% =%1D%%0 ;0? 1D( ;$@;2%01 0":=%)< #< ;>D;?< %O";>E H(D%I%)F ?(" D#>> A)(=;=>?%0$ "A D#15 <(:% D%#)$ ');21#(0 ;< ?(") <1%A <#N%E /' ?(" $( 0(1 #0A"1 ; $%<#)%$ >%0B15F 674879 D#>> "<%15% $%';">1 I;>"% (' ,jjE

63$%=#<1V1< & 63$%=#<1D%;#-;M %;.=M 61$@;>IC

=(1,3 9/,5"'#5,3 -,5" G#35&/1.

70? =;<#2 ;)#15:%1#2 #0I(>I#0B ; I%21() ;0$ ; 2(0<1;01 25;0B%< 15% I;>"% (' ;>> %>%:%01< #0 15%I%21()E a%:%:=%) 1( "<% 15% $(1 UEV D#15 :">1#A>#2;1#(0 ;0$ $#I#<#(0E

41< & P8 F ! 9 UQC41< & 41< 7 L 41< & PF ! 9 U 88Q41< & 41<BEL 41< & PL * 8O 8H 8TQ

A)*#F,): G#35&/1.

4( )%1")0 ; A;)1#2">;) );0B% (' I;>"%< ')(: ; B#I%0 I%21()F ?(" 2;0 #0$%C #01( #1 "<#0BA;)%015%<%<E 45% #1%: #0 A;)%015%<%<F () 15% );0B% ?(" D#<5 1( )%1")0 ')(: 15% I%21()F 2;0 =% %#15%) ;$("=>% () 2(>>%21#(0 (' $("=>%< U;0(15%) I%21()V )%A)%<%01#0B 15% A(<#1#(0< #0 15% ()#B#0;> I%21() 15;1?(" D#<5 1( )%1")0E 9? "<#0B ;0(15%) I%21() ;< 15% #0$%C );0B%F ?(" 2;0 )%1")0 15% %>%:%01< #0 ;0? ()$%)() %I%0 15% <;:% %>%:%01 :">1#A>% 1#:%<E 45% >%0B15 (' 15% I%21() )%1")0%$ D#>> ;>D;?< =% %O";> 1( 15%>%0B15 (' 15% #0$%CE

9%2;"<% ;0? #0$%C 15;1 )%1")0< :">1#A>% I;>"%< #< =? $%'#0#1#(0 ; I%21()F #0$#2%< %;<#>? =%B%0%);1%$ "<#0B 15% 2(>(0 (A%);1()E e(#0B <( ;>>(D< ?(" 1( A%)'(): :;0? 0#'1? #0$%C#0B 1)#2G< <"25 ;<)%I%)<#0B ; I%21() () )%1")0#0B (0>? %I%0K0":=%)%$ A(<#1#(0<E /' ?(" D#<5 1( #0$%C "A 1( 15% >;<1element in a vector, use the keyword “end.” Because MATLAB interprets “end” as a number equal to the>%0B15 (' 15% I%21()F ?(" 2;0 "<% <"=1);21#(0 () $#I#<#(0 1( #0$%C A(<#1#(0< =;<%$ (0 15% %0$ I;>"%E 70?;11%:A1 1( #0$%C D#15 ; 0":=%) >%<< 15;0 (0%F ; ');21#(0F () ; 0":=%) B)%;1%) 15;0 15% >%0B15 (' 15%

Page 13: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 13/101

vector you’r % #0$%C#0B #01( D#>> A)($"2% ;0 %))()E S(" D#>> A)(=;=>? >(<% ; :;@()#1? (' 15% A(#01< (0homework assignments from the message “Error: Index exceeds matrix dimensions.”

41< & P8 F ! 9 UQC41<DFI #$% & !41<DP8 H L L FQ #$% & P8 9 F F !Q

41<D8(L(!I #$% & P8 ! UQ41<D*I ,--.-41<D8(F(1$0I #$% &P8 9Q41<DP8(FM 1$0M 1$0NLQI #$% & P8 F ! U 9Q41<D-./$0D1$0GLI(1$0I #$% & P! 9 UQ

>?,3,): G#35&/1.

The word “slicing” seems to be standard terminology for this course even though it makes no<%0<% 1( :%E +>#2#0B #0I(>I%< )%A>;2#0B <(:% (' 15% %>%:%01< #0 (0% I%21() D#15 <(:% (' 15% %>%:%01< #0;0(15%) I%21()E 45% :(<1 #:A()1;01 15#0B 1( )%:%:=%) D5%0 <>#2#0B #< 1( =% 2;)%'"> ;=("1 D5;1 ?("

25((<% 1( (I%)D)#1%E 4( $%>%1% %>%:%01< ')(: ; I%21()F <%1 15%: %O";> 1( %:A1? =);2G%1<E H%)% ;)% 15%=;<#2 '():< (' <>#2#0B3

,E 7U#0$%CV h 9U#0$%CV45#< #< 15% :(<1 2(::(0 '():E 674879 '#)<1 %I;>";1%< 9U#0$%CVF 15%0 )%A>;2%< 7U#0$%CV D#15 #1EThe rest of “A” remains unchanged. Produces an error if B(index) and A(index) are not the <;:%>%0B15E

YE 7U#0$%CV h 9a%A>;2%< 15% %>%:%01< #0 7U#0$%CV D#15 D5;1%I%) #< <1()%$ #0 9E Q02% ;B;#0F 7U#0$%CV ;0$ 9 :"5;I% #$%01#2;> >%0B15<E

-E 7 h 9U#0$%CV45#< #< 15% :#<1;G% :;0? <1"$%01< :;G% D5%0 <>#2#0BE 45#< (I%)D)#1%< 15% I;)#;=>% 7 ;0$ <%1< #1%O";> 1( 9U#0$%CVE 7>> %>%:%01< #0 7 ;)% )%A>;2%$F #02>"$#0B 15% (0%< ("1<#$% 15% );0B% (' 9F <15% >%0B15< 2;0 =% "0%O";> D#15("1 A)($"2#0B ;0 %))()E

ZE 7U#0$%CV h kl+%11#0B ;0?15#0B %O";> 1( %:A1? =);2G%1< $%>%1%< #1E 45#< 2;0 =% "<%$ 1( <5()1%0 15% >%0B15 (' 7() $%>%1% ;>> (' 15% %>%:%01< %01#)%>?F >%;I#0B 7 ;< ;0 %:A1? I%21()E

*(01);)? 1( #0$%C#0BF ?(" 2;0 <>#2% %>%:%01< 15;1 ;)% ("1 (' =("0$< (' 15% ()#B#0;> I%21()E /' ?(";<<#B0 ; I;>"% 1( ;0 %>%:%01 15;1 $#$ 0(1 ()#B#0;>>? %C#<1F 674879 D#>> %C1%0$ 15% I%21() =? '#>>#0B ;>>#01%):%$#;1% A(<#1#(0< D#15 N%)(<E 4( <>#2% ("1<#$% 15% =("0$< (' ; I%21() (' "0G0(D0 >%0B15F "<%addition or multiplication with “end.”

41<8 & P8 F ! 9 UQC41<L & PO L H * T 8OQC41<8DP8 L HQI & 41<8DF(1$0I 41<8 & P! 9 ! U UQ41<8D8(FI & 41<LD1$0(N8(HI 41<8 & P8O T * 9 UQ41<LDL(1$0I & 41<8 41<L & PO 8 F ! 9 UQ41<8 & 41<LD8(L(1$0I 41<8 & PO H TQ41<LDP8 H !QI & PQ 41<L & PL H 8OQ41<8D1$07LI & * 41<8 & P8 F ! 9 U O *Q

The possibilities are endless…

Page 14: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 14/101

%&)3(5#)(5,): G#35&/1.

674879 "<%< <O";)% =);2G%1< '() @"<1 ;=("1 %I%)?15#0BE S(" 2;0 ;><( "<% 15%: 1( 2(02;1%0;1%I%21()<F () 2(:=#0% :">1#A>% <:;>> I%21()< #01( (0% >;)B% (0%E +#:A>? 2)%;1% ; I%21() #0 15% <1;0$;)$

:;00%) "<#0B I%21()< ;< 15% %>%:%01< );15%) 15;0 <2;>;) I;>"%<E 4( 2(02;1%0;1% I%21()< 2(>":0KD#<%F<%A;);1% 15% $#''%)%01 %>%:%01< D#15 <%:#2(>(0<E

41<8 & P8 ! UQC41<L & P* TQC53@V1< & P41<LM 41<8Q 53@V1< & P* T 8 ! UQcolVec = [vec1’; vec2’] <.6V1< & P8C !C UC *C TQ

C&:,3(? A)*#F,):.

+( ';)F D% 5;I% (0>? $%;>1 D#15 $;1; (' 1?A% $("=>%F )%A)%<%01#0B )%;>F :%;<");=>% 0":%)#2;>

I;>"%<E H(D%I%)F ;0(15%) $;1; 1?A% ')%O"%01>? "<%$ #0 674879 #< 1?A% >(B#2;>E 8(B#2;> $;1; 2;0 (0>? 1;G%1D( '():<3 1)"% () ';><%E /0 :(<1 2;<%<F 15% 0":=%) (0% )%A)%<%01< 1)"%F D5#>% 15% 0":=%) N%)(#0$#2;1%< ';><%L 5(D%I%)F 674879 ;21";>>? #01%)A)%1< ;0?15#0B 0(1 %O";> 1( N%)( ;< 1)"%F #02>"$#0B0%B;1#I% 0":=%)< ;0$ <1)#0B<E

P5%0 "<#0B ;0? (' 15% %CA)%<<#(0< =%>(DF G%%A #0 :#0$ 15;1 15% 1D( (=@%21< ?(" D#<5 1(2(:A;)% :"<1 =% $#:%0<#(0;>>? /eRJ4/*78E 711%:A1#0B 1( 2(:A;)% 1D( I%21()< (' "0%O";> >%0B15 D#>>A)($"2% ;0 %))()E

7 >(B#2;> %CA)%<<#(0 D#>> B%0%);1% ; 2(>>%21#(0 (' >(B#2;> #0$#2;1#0B D5%)% 15% <1;1%:%01 #< 1)"%;0$ D5%)% #1 #< ';><% U(0% '() 1)"% ;0$ N%)( '() ';><%VE 8(B#2;> %CA)%<<#(0< B%0%);>>? #0I(>I% 2(:A;)#<(0<;0$ 2;0 1;G% 0":%)("< '():<3

hhF %O";> 1( mF B)%;1%) 15;0 nF >%<< 15;0 mhF B)%;1%) 15;0 () %O";> 1( nhF >%<< 15;0 () %O";> 1( ohF 0(1 %O";> 1(

The tilde (~) is always used to refer to the word “not.” When preceding a logica > 2(>>%21#(0F #125;0B%< %I%)? 1)"% 1( ';><% ;0$ %I%)? ';><% 1( 1)"%E J#'1?p

41<8 & P8 F ! 9 UQC

41<8 && F #$% & PO 8 O O OQ D6.@3<#6I41<8 W F #$% & PO O 8 8 8Q

B(10,):

/0$%C#0B D#15 >(B#2;>< #< I%)? $#''%)%01 ')(: #0$%C#0B D#15 $("=>%<E 45% A(<#1#(0 0":=%)< ('I;>"%< =%#0B #0$%C%$ ;)% )%A)%<%01%$ =? 15%&$"'#( (' $("=>% #0$#2%< ;0$ 15% )*(+,+*- -'/0#%( (' >(B#2;>#0$#2%<E 45"<F ; 1)"% ;1 A(<#1#(0 15)%% #0 ; >(B#2;> 2(>>%21#(0 D#>> #0$%C 15% %>%:%01 #0 A(<#1#(0 15)%%

Page 15: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 15/101

15% 2(>>%21#(0 =%#0B #0$%C%$E 45% #0$%C :;? =% <5()1%) 15;0 15% I%21() =%#0B #0$%C%$F ="1 0(1 >(0B%)E_() <(:% )%;<(0F >(B#2;>< 2;0 %I%0 =% "<%$ 1( #0$%C (15%) >(B#2;><E _() <(:% )%;<(0F 15#< #< G0(D0 ;<:;<G#0BE

41<8 & P8 F ! F UQC41<8D41<8&&FI #$% & PF FQ

41<8D41<8 X& !I #$% & P! UQ41<8D;-/1 2#6%1 ;-/1I #$% & P8 !Q

6;<G#0B 2;0 =% "<%$ D#15 %I%0 :()% A)%2#<#(0 "<#0B ;0$ UqV ;0$ () UrVE 45%<% 2;0 =% "<%$ 1(2(:=#0% 2(>>%21#(0< (' >(B#2;>< 1( '(): ; '#0;> #0$%C )%A)%<%01#0B ;>> (' 15%:E f"<1 )%:%:=%) 15%<%<%%:#0B>? );0$(: )">%<3

,E An “and” statement is only true if all of the elements are true. YE An “or” statement is only false if all of the elements are false.

P5%0 :">1#A>% >(B#2;> 2(>>%21#(0< ;)% 2(:=#0%$ "<#0B q () rF %;25 %>%:%01 #0 15% 2(>>%21#(0< #<2(:A;)%$ #0$#I#$";>>? 1( 15% 2())%<A(0$#0B %>%:%01< #0 15% (15%) 2(>>%21#(0<E 45#< <1);1%B? 2;0 =% "<%$1( :;G% ; <#0B>% #0$%C 15;1 :;125%< :;0? $#''%)%01 A;);:%1%)<E

41<8 & P8 F ! 9 UQC41<8 W8 Y 41<8 X& 9 #$% & PF ! 9QP;-/1 2#6%1 ;-/1Q Z P2#6%1 2#6%1 ;-/1Q #$% & P8 O 8QD;-/1 Z 2#6%1I Y D2#6%1 Y ;-/1I #$% & O

<1#J7? D7)35,&)1.

X%21() +1"''3

:#0UCV – )%1")0< 15% <:;>>%<1 %>%:%01 #0 15% 2(>>%21#(0 UJ(1%3 #' 15% :#0#:": I;>"% (22")<:">1#A>% 1#:%<F :#0UV ;0$ :;CUV D#>> )%1")0 (0>? 15% '#)<1 #0<1;02%V

kI;>"%F #0$%Cl h :#0UCV – )%1")0< 15% <:;>>%<1 %>%:%01 ;>(0B D#15 #1< A(<#1#(0 0":=%) :;CUCV – )%1")0< 15% >;)B%<1 %>%:%01 #0 15% 2(>>%21#(0 kI;>"%F #0$%Cl h :;CUCV – )%1")0< 15% >;)B%<1 %>%:%01 ;>(0B D#15 #1< A(<#1#(0 0":=%) <()1UCV – <()1< 15% %>%:%01< #0 ;<2%0$#0B ()$%) k0%DgF #0$%Cl h <()1UCV – )%1")0< C #0 ;<2%0$#0B ()$%) ;>(0B D#15 ; I%21() 2(01;#0#0B 15% A(<#1#(0

0":=%)< (' 15% ()#B#0;> C 1( D5#25 %;25 I;>"% 2())%<A(0$< '>#A>)UCV – '>#A< C >%'1K1(K)#B51 x’ – 1);0<A(<%< C U)(D I%21() 2(>":0 I%21()V :($UCF0":V – )%1")0< 15% )%:;#0$%) #' C #< $#I#$%$ =? 0":

)("0$UCV – )("0$< C "A () $(D0 2%#>UCV – )("0$< C "A 1( 15% 0%C1K5#B5%<1 #01%B%) #' C #< ');21#(0;> '>(()UCV – )("0$< C $(D0 1( 15% 0%C1K>(D%<1 #01%B%) #' C #< ');21#(0;> (0%<UCF?V – 2)%;1%< ;0 ;));? (' (0%< (' $#:%0<#(0 CF? UM<% , '() C () ? 1( B%0%);1% I%21()<V N%)(<UCF?V – 2)%;1%< ;0 ;));? (' N%)(< (' $#:%0<#(0 CF? 1)"%UCF?V – 2)%;1%< ;0 ;));? (' >(B#2;> 1)"%< (' $#:%0<#(0 CF? ';><%UCF?V – 2)%;1%< ;0 ;));? (' >(B#2;> ';><%< (' $#:%0<#(0 CF? <":UCV – 2(:A"1%< 15% <": (' C

Page 16: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 16/101

Page 17: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 17/101

+%21#(0 _(")3 7));?<

P5#>% I%21()< ;)% :%)%>? (0%K$#:%0<#(0;> 2(>>%21#(0< (' $;1; <1()%$ ;< )(D< () 2(>":0<F ;));?<;)% 1D(K$#:%0<#(0;> 2(>>%21#(0< <1()%$ ;< B)#$< 2(01;#0#0B =(15 )(D< ;0$ 2(>":0<E 45%? (A%);1% #0#F(35?6 5"# 1('# -(6 ;< I%21()< %C2%A1 '() ; '%D :#0() $#''%)%02%<E 7>15("B5 ;));?< ;)% <"AA(<%$ 1( =%different from matrices, they’re actually not. Arrays can contain doubles, logicals, and various other data1?A%<E

P5#>% 674879 #< 2;A;=>% (' <1()#0B $;1; #0 :()% $#:%0<#(0< 15;0 ;)% )%;$#>? "0$%)<1;0$;=>%F15#< 2(")<% 0%I%) #0I(>I%< $;1; 2(>>%21#(0< (' :()% 15;0 1D( $#:%0<#(0<F %C2>"$#0B #:;B%<E

%/#(5,): 9//(61.

7));?< ;)% 2)%;1%$ "<#0B <O";)% =);2G%1< #0 :"25 15% <;:% D;? ;< I%21()<E +#:A>? %01%) 15%#0$#I#$";>%*1( (' 15% 2(>>%21#(0 <%A;);1%$ =? <%:#2(>(0<E S%<F 15% <%:#2(>(0 ;><( 5;< :;0? $#I%)<%"<%<E 7));?< :"<1 ;>D;?< =% )%21;0B">;)L #' ;1 ;0? A(#01 674879 ;11%:A1< 1( 2)%;1% ;0 ;));? 15;1 #< 0(1)%21;0B">;)F #1 D#>> A)($"2% ;0 %))()E

#-- & P8 L FC H ! *C 9 T UQ #$% & 1 2 34 5 67 8 9

#--L & P8 LC F HC ! *Q #$% & 1 23 45 6

#--F & P8 L FC H !C * 9 TQ ,--.-

A)*#F,): 9//(61.

45% #1%:< #0 ;));?< ;)% ()B;0#N%$ =;<%$ (0 15%#) >(2;1#(0 ;< $%1%):#0%$ =? )(D< ;0$ 2(>":0<E9(15 )(D< ;0$ 2(>":0< =%B#0 ;1 (0% ;0$ #02)%;<% ;< ?(" :(I% $(D0 ;0$ 1( 15% )#B51F )%<A%21#I%>?ER>%:%01< ;)% #0$%C%$ =? 15%#) )(D 0":=%)< '(>>(D%$ =? 15%#) 2(>":0 0":=%)<F D#15 ; 2(::; #0=%1D%%0E 4( #0$%C ;>> )(D< () ;>> 2(>":0<F )%A>;2% 15% )(D () 2(>":0 0":=%)< #0 15% #0$%C D#15 ; 2(>(0

<?:=(>E S(" 2;0 ;><( use the keyword “end” to access the final element in a particular row or column, or=(15 #' #1 :;G%< ?(" 5;AA?E

#-- & P8 L FC H ! *C 9 T UQ #$% & 1 2 34 5 67 8 9

#--DLMFI #$% & *#--DLM(I #$% & PH ! *Q

Page 18: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 18/101

#--D(MLI #$% & PLC!CTQ#--D1$0M1$0I #$% & U

>2?,55,): 9//(61 ,)5& 4(?K#1 ()* L7(/5#/1.

Don’t bother memorizing these. You can easily reproduce them with some practice.

#--D8(-./$0D1$0GLIM(I [.= >#62#--D-./$0D1$0GLI(1$0M(I \.;;.A >#62#--D(M8(-./$0D1$0GLII ]12; >#62#--D(M-./$0D1$0GLI(1$0I ^3@>; >#62#--D-./$0D1$0GLI(1$0M-./$0D1$0GLI(1$0I \.;;.AN-3@>; _/#-;1-

MATLAB’s Secret Trick:

7>15("B5 ;));?< ;)% $#<A>;?%$ #0 15% 2(::;0$ D#0$(D ;< 1D(K$#:%0<#(0;> :;1)#2%< (' I;>"%<F674879 ;21";>>? <1()%< 15% #0'():;1#(0 ;< ; I%)? >(0B 2(>":0 I%21()E /1 0":=%)< 15% %>%:%01< =?)%;$#0B $(D0 15% 2(>":0< (0% ;1 ; 1#:%F :%;0#0B 15;1 ;));?< 2;0 ;21";>>? =% #0$%C%$ ;< #' 15%? D%)%I%21()<E 45#< 2;0 =% "<%'"> 1( )%:%:=%) =%2;"<% #1 ;>>(D< ?(" 1( )%<5;A% ;));?< #01( I%21()< I%)? %;<#>?E

#-- & P8 L FC H ! *C 9 T UQ #$% & 1 2 34 5 67 8 9

#--D(I #$% & P8CHC9CLC!CTCFC*CUQ#--DHI #$% & L#--DTI #$% & *

>?,3,): 9//(61.

9? <>#2#0B ;));?< #0 2)%;1#I% D;?<F ?(" 2;0 $( ;>> <()1< (' #01%)%<1#0B 15#0B< <"25 ;< <D;AA#0B)(D< () 2(>":0<F :#))()#0BF $%>%1#0B %>%:%01<F ;0$ '>#AA#0B 15#0B< "A<#$% $(D0E 6;G% <")% ?(" G0(D;0$ "0$%)<1;0$ 15% '#)<1 1D(F ;< 15%? ;)% %C1)%:%>? "<%'">E

#--D(M(I & #--D(M1$0(N8(8I `3--.-% 612; ;. -3@>;#--D(M(I & #--D1$0(N8(8M(I a63=% /=%301 0.?$#--DL(L(1$0M(I & #--D1$0(NL(LM(I ^141-%1% ;>1 141$N$/A51-10 -.?%#--D8(F(1$0ML(L(1$0I & PQ b161;1% 141-) ;>3-0 -.? #$0 %1<.$0 <.6/A$

Page 19: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 19/101

%&)3(5#)(5,): 9//(61.

7));?< 2;0 =% 2(02;1%0;1%$ 5()#N(01;>>? () I%)1#2;>>? @"<1 >#G% I%21()<E Q02% ;B;#0F ;0? 2(::;0$15;1 D(">$ A)($"2% ; 0(0K)%21;0B">;) ;));? )%<">1< #0 ;0 %))()E

P#--8M #--LQ c.$<#;1$#;1% >.-3d.$;#66)P#--8C #--LQ c.$<#;1$#;1% 41-;3<#66)

C&:,3(? A)*#F,): ()* B(10,):.

Seriously, it’s the ($/# 15#0BE

#-- & P8 LC F HQC #$% & 1 23 4

#-- W F #$% & PO OC O 8Q#--DA.0D#--MLII&&OI&9 #$% & P8 9C F 9Q

P5%0 ?(" 0%%$ 1( $%1%):#0% D5#25 %>%:%01< :%%1 :">1#A>% (I%)>;AA#0B 2(0$#1#(0<F ?(" 2;0"<% ;0$ UqV ;0$ () UrV 1( 2(:=#0% :">1#A>% <%1< (' >(B#2;><E

A.0D#--MLIe&O Y #-- W& ! f66 .00 161A1$;% @-1#;1- ;>#$ .- 1_/#6 ;. 2341#-- W 8O Z #--&&9 f66 161A1$;% @-1#;1- ;>#$ 8O .- 1_/#6 ;. 9

=(1,3 9/,5"'#5,3.

7>> ;)#15:%1#2 2;>2">;1#(0< #0I(>I#0B ;));?< ;)% A%)'():%$ %>%:%01K=?K%>%:%01E a%:%:=%) 1(

"<% 15% $(1 D#15 :">1#A>#2;1#(0 ;0$ $#I#<#(0E

#-- & P8 LC F HQ #$% & 1 23 4

#--L & P! *C 9 TQC #$% & 5 67 8

#-- 7 #--L #$% & P* TC 8O 8LQ#-- BE #--L #$% & P! 8LC L8 FLQ#-- – 8 #$% & PO 8C L FQ

!/()12&1,): ()* M&5(5,): 9//(61.

f"<1 ;< 15% ;A(<1)(A5% 1")0< )(D I%21()< #01( 2(>":0 I%21()<F #1 ;><( 1);0<A(<%< 15% )(D< ;0$2(>":0< #0 ;));?<E 45% '#)<1 2(>":0 =%2(:%< 15% '#)<1 )(DF 15% <%2(0$ 2(>":0 =%2(:%< 15% <%2(0$ )(DF%12E 45#< #< 0(1 1( =% :#<1;G%0 D#15 )(1;1#0B ;0 ;));? 2>(2GD#<% () 2("01%)2>(2GD#<%F )%O"#)%< =(151);0<A(<#1#(0 ;0$ #0$%C#0BE

Page 20: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 20/101

arr’ #$% & P8 H 9C L ! TC F * UQ#--D1$0(N 1:1,:)’ ^.;#;1% <6.<g?3%1#--D(M1$0(N 1:1)’ ^.;#;1% <./$;1-<6.<g?3%1#--D1$0(N8(8M1$0(N8(8I ^.;#;1% 8TO 01@-11%

M#1"(2#HI

45#< '"021#(0 ;>>(D< ?(" 1( 25;0B% 15% 0":=%) (' )(D< ;0$ 2(>":0< #0 ;0 ;));? D#15("1 ;>1%)#0B#1< (I%);>> <#N%E 674879 '#>>< 15% <A;2%< #0 15% 0%D ;));? #0 15% <;:% ()$%) ;< 15% ()#B#0;>F 0;:%>?)%;$#0B $(D0 15% 2(>":0< (0% ;1 ; 1#:%E 45"< ;))UZV D#>> =% %O";> 1( 0%D[;))UZVE

You probably won’t be using reshape() more than once or twice.

$1?D#--I & -1%>#=1D#--M $1?K-.?%M $1?K<.6/A$%I

#--L & P8 LC F HC ! *Q #$% &

1 23 45 6

$1?K#-- & -1%>#=1D#--MLMFI #$% & 1 5 43 2 6

<1#J7? D7)35,&)1.

(0%<UCF?V – 2)%;1%< ;0 ;));? (' (0%< (' $#:%0<#(0 CF? UM<% , '() C () ? 1( B%0%);1% I%21()<V N%)(<UCF?V – 2)%;1%< ;0 ;));? (' N%)(< (' $#:%0<#(0 CF?

1)"%UCF?V – 2)%;1%< ;0 ;));? (' >(B#2;> 1)"%< (' $#:%0<#(0 CF? ';><%UCF?V – 2)%;1%< ;0 ;));? (' >(B#2;> ';><%< (' $#:%0<#(0 CF? :;B#2UCV—2)%;1%< ; :;B#2 <O";)% (' $#:%0<#(0 C k)(DF2(>l h <#N%U;))V—)%1")0< 15% 0":=%) (' )(D< ;0$ 2(>":0< #0 15% #0A"1 ;));?

45% '(>>(D#0B '"021#(0< D()G $#''%)%01>? D#15 ;));?< 15;0 D#15 I%21()<E 9"#>1K#0 '"021#(0< B%0%);>>? 1)%;1;));?< ;< #0$#I#$";> 2(>":0 I%21()< ;0$ %CA)%<< 15%#) ("1A"1< ;< )(D I%21()<E

kI;>"%F#0$%Cl h :#0U;))V—)%1")0< ; )(D I%21() (' 15% :#0#:": I;>"%< #0 %;25 2(>":0E 45%<%2(0$ ("1A"1 2(01;#0< 15% )(D 0":=%) (' 15% :#0#:": I;>"% #0 %;25 2(>":0

kI;>"%F#0$%Cl h :;CU;))V—)%1")0< ; )(D I%21() (' 15% :;C#:": I;>"%< #0 %;25 2(>":0E 45%<%2(0$ ("1A"1 2(01;#0< 15% )(D 0":=%) (' 15% :;C#:": I;>"% #0 %;25 2(>":0

k<()1%$[;))F#0$%Cl h <()1U;))V—<()1< %;25 2(>":0 (' 15% ;));? #0 ;<2%0$#0B ()$%) ')(: 1(A 1(=(11(:E 45% <%2(0$ ("1A"1 2(0<#<1< (' 15% #0$#2%< "<%$ 1( <()1 %;25 2(>":0 2(02;1%0;1%$1(B%15%) ;< ;0 ;));?

<":U;))V —)%1")0< ; )(D I%21() (' 15% <": (' %;25 2(>":0 #0 15% ;));? :%;0U;))V —)%1")0< ; )(D I%21() (' 15% :%;0 (' %;25 2(>":0 #0 15% ;));?

Page 21: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 21/101

4( $%1%):#0% 15% ;=<(>"1% :#0#:":F :;C#:":F <":F () :%;0 (' ;0 ;));?F <#:A>? 2;>> 15% )%<A%21#I%'"021#(0< 1D#2%E

kI;>"%F #0$%Cl h :;CU:;CU;))VV—)%1")0< 15% ;=<(>"1% :;C#:": (' 15% ;));? ;>(0B D#15 #1<2(>":0 0":=%)

kI;>"%F #0$%Cl h :#0U:#0U;))VV—)%1")0< 15% ;=<(>"1% :#0#:": (' 15% ;));? ;>(0B D#15 #1< 2(>":00":=%)

<":U<":U;))VV —)%1")0< 15% (I%);>> <": (' 15% %>%:%01< #0 15% ;));? :%;0U:%;0U;))VV —)%1")0< 15% (I%);>> :%;0 (' 15% %>%:%01< #0 15% ;));?

/ G0(D 15%<% %CA>;0;1#(0< 2;0 =% <(:%D5;1 2(0'"<#0BF <( $( ?(")<%>' ; ';I() ;0$ A>;? ;)("0$D#15 15% :#0UVF :;CUVF :%;0UVF ;0$ <()1UV '"021#(0< '() ; '%D :#0"1%<E 7>> '(") ')%O"%01>? ;AA%;) (05(:%D()G< ;0$ 1%<1 A)(=>%:<E

Page 22: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 22/101

+%21#(0 _#I%3 +1)#0B<

X%21()< ;0$ ;));?< ;)% (0>? "<%'"> '() ()B;0#N#0B <%1< (' $("=>%< ;0$ >(B#2;><E J(DF D% D#>> =%$%;>#0B D#15 ; 0%D $;1; 1?A% 2;>>%$ 25;) U<5()1 '() 25;);21%)VE M<#0B 25;);21%)< ;>>(D< ?(" 1( <%1I;)#;=>%< ;0$ ("1A"1< %O";> 1( :%;0#0B'"> D()$< ;0$ A5);<%< );15%) 15;0 @"<1 0":=%)<E

7 <1)#0B #< ; I%21() (' 0":=%)< 15;1 )%A)%<%01 15% 25;);21%)< ;0$ <?:=(>< (0 ?(") G%?=(;)$E674879 #$%01#'#%< 15%<% 0":=%)K25;);21%) 2(:=#0;1#(0< =;<%$ (0 ; A)%$%1%):#0%$ <%1 (' 2(0I%)<#(0<2;>>%$ ;0 7<2## 4;=>%E

45%columns labeled “Dec” contain the ascii codes for the corresponding red characters in thecolumns labeled “Char.” For example, the ascii code for a capital Z is 90. Note that the code for a>(D%)2;<% >%11%) #< %C;21>? -Y A>"< #1< "AA%)2;<% %O"#I;>%01E 45% ;<2## 2($% '() ; <A;2% #< -YE

45% :(<1 #:A()1;01 15#0B 1( )%:%:=%) ;=("1 <1)#0B< #< 15;1 15%? '"021#(0 %C;21>? >#G% I%21()< #0most scenarios. To better understand the functionality of strings, we’ll be looking at a lot of examples.

Page 23: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 23/101

Page 24: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 24/101

A)*#F,): >5/,):1.

S(" 2;0 #0$%C 15% %>%:%01< #0 ; <1)#0B 15% <;:% D;? ?(" D(">$ D#15 ; I%21()E f"<1 G%%A #0 :#0$15;1 674879 0(D #01%)A)%1< RXRaS4H/J! #0 15% <1)#0B ;< ; <%A;);1% %>%:%01F #02>"$#0B <A;2%< ;0$2(::;<E /0$%C#0B <1)#0B< )%1")0< 15% ;21";> 25;);21%)<F 0(1 $("=>%<E

str = ‘Adam and Eve’; %;-DLI #$% & ‘d’ %;-D!I ans = ‘ ‘ %;-DF(9I ans = ‘am an’ 61$@;>D%;-I #$% & 8L

>?,3,): >5/,):1.

/' ?(" 2;0 <>#2% I%21()<F ?(" 2;0 <>#2% <1)#0B<E /' ?(" <>#2% =%?(0$ 15% =("0$< (' 15% ()#B#0;> <1)#0BF674879 D#>> '#>> 15% #01%):%$#;1% <A;2%< D#15 ;<2## N%)(<F 0(1 -Y<E

str1 = ‘Isaac’; str2 = ‘Rebecca’; %;-8DF(1$0I & %;-LDL(HI str1 = ‘Isebe’ %;-LD8(!I & %;-8 str2 = ‘Isaacca’ %;-8 & %;-LD8(1$0N8I str1 = ‘Rebecc’ %;-8DP8 FQI & PQ str1 = ‘sac’

str3 = ‘Abram’;

str3(8) = ‘O’ ans = ‘Abram O’ 0./561D%;-FD9II #$% & O

%&)3(5#)(5,): >5/,):1.

S(" (0>? 0%%$ 1( D())? ;=("1 2(02;1%0;1#0B <1)#0B< 5()#N(01;>>?E 4%250#2;>>?F 15%? 2;0 =%2(02;1%0;1%$ I%)1#2;>>? 1( :;G% ')%;G? <1)#0B ;));?<F ="1 $(#0B <( #< I#)1";>>? "<%>%<<E s%%A #0 :#0$ 15;1<1)#0B< ;)% 2(02;1%0;1%$ @"<1 >#G% I%21()<F <( 674879 D#>> 0(1 ;$$ <A;2%< 1( <%A;);1% D()$<E

You can also concatenate strings with doubles since they’re virtually the same thing. MATLAB;>D;?< )%1;#0< 15% <1)#0B '():;1 ;'1%) 2(02;1%0;1#(0E

tstr2 = ‘Ham’; str3 = ‘Japheth;’ P%;-8 %;-L %;-FQ #$% & ‘ShemHamJapheth’ P%;-8 *!Q ans = ‘ShemA’ P*! %;-8Q ans = ‘AShem’

Page 25: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 25/101

C&:,3(? A)*#F,): -,5" >5/,):1.

+1)#0B< 2;0 =% "<%$ #0 >(B#2;> %CA)%<<#(0< :"25 >#G% I%21()<E 45% (0>? $#''%)%02% #< 15;1 ?(" 2;00(D :;G% 2(:A;)#<(0< =%1D%%0 25;);21%)< ;0$ $("=>%<E a%:%:=%) 15;1 2(:A;)#0B I%21()< ('different lengths produces an error. It is impossible with strings of unlike lengths as well; there’s a

<A%2#;> '"021#(0 '() 15;1E

8(B#2;> %CA)%<<#(0< ;)% I%)? "<%'"> '() $%1%):#0#0B 2;A#1;> ;0$ >(D%)2;<% >%11%)< ;0$ '()$#''%)%01#;1#0B =%1D%%0 >%11%)< ;0$ <?:=(><E Q02% ;B;#0F ?(" 2;0 >(2;1% %>%:%01< 15;1 '">'#>> :">1#A>%>(B#2;> 2(0$#1#(0< "<#0B ;0$ UqV () ()UrVE

str1 = ‘Jacob’; str2 = ‘Rachel’; str1==’c’ #$% & PO O 8 O OQ%;-L&&TL #$% & P8 O O OQ%;-8&&%;-L ,--.-

%;-W&*! Y %;-X&UO c#=3;#6 61;;1-%%;-W&U9 Y %;-X&8LL ].?1-<#%1 61;;1-%D%;-W&*! Y %;-X&UOIZD%;-W&U9 Y %;-X&8LLI f66 61;;1-%

>5/3'2HI ()* >5/3'2,HI.

45% <1)2:AUV '"021#(0 ;>>(D< ?(" 1( 2(:A;)% <1)#0B< (' "0%O";> >%0B15E 45#< #< #:A()1;01=%2;"<% ;11%:A1#0B 1( "<% >(B#2;> %CA)%<<#(0< 1( $( <( A)($"2%< ;0 %))()E +1)2:AUV ("1A"1< ; >(B#2;> , ()j )%A)%<%01#0B D5%15%) 15% 1D( #0A"1 <1)#0B< ;)% %C;21>? %O"#I;>%01E

+1)2:AUV #< 2;<%K<%0<#1#I%E 45%)% #< ;0(15%) ="#>1K#0 '"021#(0F <1)2:A#UVF 15;1 A%)'():< 15% <;:%'"021#(0 D5#>% #B0()#0B 2;<%

+1)2:AUV ;0$ <1)2:A#UV 2;0 ;><( =% "<%$ 1( 2(:A;)% ; <1)#0B D#15 ; 2%>> ;));? (' <1)#0B<F #0 D5#252;<% 15%? ("1A"1 ; I%21() (' >(B#2;><E

str1 = ‘Ephraim’; str2 = ‘Manasseh’; str3 = ‘Ephraim’; str4 = ‘manasseh’;

%;-<A=D%;-8M %;-LI #$% & O%;-<A=D%;-8M %;-FI #$% & 8%;-<A=D%;-LM%;-HI #$% & O%;-<A=3D%;-LM%;-HI #$% & 8

Page 26: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 26/101

Page 27: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 27/101

[C,D] = strtok(B,’ ‘) C = ‘el’ D = ‘ Cain’

[E,F] = strtok(D,’ ‘) E = ‘Cain’ F = ‘’

C&-#/HI ()* <22#/HI.

45% >(D%)UV ;0$ "AA%)UV '"021#(0< 1;G% #0 ; <1)#0B ;0$ 2(0I%)1 ;>> >%11%)< 1( >(D%)2;<% ()"AA%)2;<% >%11%)<F )%<A%21#I%>?E 9%2;"<% 15%? #B0()% <A%2#;> 25;);21%)< #0 <1)#0B<F 15%? ;)% B%0%)"<%'">E

>&?K,): B(*?,N O/&N?#'1.

_() <(:% )%;<(0F 6;$>#= A)(=>%:< ;)% I%)? A(A">;) #0 <1)#0BK)%>;1%$ $)#>> A)(=>%:<E 45%$#''#2">1? ;)#<%< ')(: 15% 2(02%A1 (' )%A>;2#0B A;)1 (' ; <1)#0B D#15 ;0(15%) <1)#0B (' "0%O";> >%0B15E*(0<#$%) 15% '(>>(D#0B 6;$>#= <%01%02%3

str = ‘I can do all things through @ who strengthens me.’

A typical problem may ask you to replace the ‘@’ symbol with the word ‘Christ’. Unfortunately,<#:A>? <>#2#0B >%11%)< #01( 15% ()#B#0;> <1)#0B D#>> (I%)D)#1% 15% %0$ (' 15% <%01%02% );15%) 15;0 #0<%D()$ #0 A>;2% U@"<1 15#0G (' 15% <;:% A)(=>%: "<#0B I%21()< #0<1%;$ (' <1)#0B<VE S(" :"<1 15%)%'()% "<%%#15%) <1)1(GUV () :;0";> 2(02;1%0;1#(0 1( ;22(:A>#<5 15% #0<%)1#(0E

a%:%:=%) 15;1 15% '#0$UV '"021#(0 )%1")0< ; I%21() (' ;>> 1)"% A(<#1#(0<F 0(1 :%)%>? 15% '#)<1 (0%E

index = find(str==’@’) C3$01' & 3$01'D8IC%;- & P%;-D8(3$01'N 1), ‘Christ’, str(index+1:end)]; "#

[A,B] = strtok(str, ‘@’); str = [A, ‘Christ’, B(2:end)];

Page 28: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 28/101

+%21#(0 +#C3 *(0$#1#(0;><

*(0$#1#(0;> <1;1%:%01< ;>>(D ?(" 1( $%1%):#0% D5%15%) () 0(1 1( )"0 ; 2%)1;#0 =>(2G (' 2($%=;<%$ (0 <(:% 0(0K predetermined information. Basically, it’s what you wish you could have been using'() ;>> 15% A)%I#("< 5(:%D()G ;<<#B0:%01<E *(0$#1#(0;>< 2(:% #0 1D( '():< —#' ;0$ <D#125 <1;1%:%01<F="1 G0(D#0B <D#125 <1;1%:%01< #< :()% "<%'"> 15;0 ;=<(>"1%>? 0%2%<<;)?E

AJ >5(5#'#)51.

7>> #' <1;1%:%01< ;)% 2($%$ #0 15% '(>>(D#0B =;<#2 '():;13

32 X6.@3<#6 1'=-1%%3.$WX<.01 56.<gW

1$0

MATLAB will automatically turn the words “if” and “end” blue to designate them as markersA%)1;#0#0B 1( 15% 2($% =>(2G #0 =%1D%%0 15%:E 674879 '#)<1 %I;>";1%< 15% >(B#2;> %CA)%<<#(0 1( 15% )#B5of “if.” If the statement is true, the code block between “if” and “end” is run as if the conditionalstatement did not exist. Otherwise, MATLAB jumps from “if” to “end” and i B0()%< 15% 2($% #0 =%1D%%0E

More complicated conditionals can be created by adding the keywords “elseif” and “else.” Elseif<1;1%:%01< '"021#(0 >#G% %C1); #' %CA)%<<#(0< U>(B#2;>, D;< ';><%F ="1 :;?=% >(B#2;>Y #< 1)"%VE S(" 2;05;I% ;< :;0? %><%#' <1;1%:%01< ;< ?(" D;01 ="1 %;25 :"<1 2(01;#0 #1< (D0 2())%<A(0$#0B 2($% =>(2GE /'

?(" '#0$ 15;1 :">1#A>% <1;1%:%01< 2(01;#0 15% <;:% 2($% =>(2GF ?(" <5(">$ 2(0<#$%) 2(:=#0#0B 15%:#01( (0% >(B#2;> <1;1%:%01 "<#0B () UrVE

70 %><% <1;1%:%01F #' ?(" "<% (0%F :"<1 =% 15% '#0;> <1;1%:%01 #0 ?(") (I%);>> 2(0$#1#(0;>E /1'"021#(0< >#G% ;0 %><%#' <1;1%:%01 15;1 #< ;"1(:;1#2;>>? %I;>";1%$ ;< 1)"%E H(D%I%)F ;0 %><% <1;1%:%01D#>> =? $%'#0#1#(0 (0>? =% )"0 #' ;>> A)%2%$#0B 2(0$#1#(0;> <1;1%:%01< ;)% %I;>";1%$ ;< ';><%E

45% ()$%) (' 2(0$#1#(0;> <1;1%:%01< #< %C1)%:%>? #:A()1;01 =%2;"<% 674879 D#>> )"0 (0>? 15%2($% =>(2G 2())%<A(0$#0B 1( 15% _/a+4 1)"% >(B#2;> %CA)%<<#(0E 45"<F #1 D#>> 0(1 %I;>";1% ;0? %CA)%<<#(0<following the first true one and will skip to “end” instead.

Finally, EVERY conditional statement (if or switch) must have a corresponding “end.” Failing toinclude enough “end”s will cause an error. MATLAB automatically aligns any “end” you type with the0%;)%<1 $%<#B0;1%$ 2(0$#1#(0;> <1;1%:%01E

i2 X6.@3<#6 1'=-1%%3.$8WX<.01 56.<g8W

16%132 X6.@3<#6 1'=-1%%3.$LWX<.01 56.<gLW

Page 29: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 29/101

16%132 X6.@3<#6 1'=-1%%3.$FWX<.01 56.<gFW

16%1X<.01 56.<gHW

1$0

P#15#* %&)*,5,&)(?1.

9%>#%I% #1 () 0(1F ?(" 2;0 ;21";>>? A>;2% 2(0$#1#(0;>< /J+/eR (15%) 2(0$#1#(0;>< E +(:%1#:%<F0%<1#0B 2(0$#1#(0;>< #< 15% (0>? D;? 1( <(>I% ; A;)1#2">;) A)(=>%:E 6()% ')%O"%01>?F 5(D%I%)F ?(" 2;0"<% #1 1( :;G% ?(") 2($% :()% >%B#=>%F A)%11?F ;0$W() 2((>E *(0<#$%) 15% '(>>(D#0B %C;:A>%3

:-3;1 # 2/$<;3.$ ;>#; ;#g1% 3$ # 41<;.- #$0 <>1<g% ;. %11 32 #66 3;% 161A1$;%#-1 =1-21<; %_/#-1% 51;?11$ * #$0 LF ;>#; #-1 $.; 0343%3561 5) 2./-B [>1

2/$<;3.$ %>./60 ./;=/; # 6.@3<#6 ;-/1 .- 2#6%1B

2/$<;3.$ ./;& S?.-023%>D41<I./; & 2#6%1C32 #66DA.0D%_-;D41<IM8II&&O

32 #66D41<W*I32 #66D41<XLFI

32 #66DA.0D41<MHIe&OI./; & ;-/1C

1$0

1$01$0

1$01$0

7< ?(" 2;0 <%%F 15#< 2($% #< :"25 %;<#%) 1( "0$%)<1;0$ 15;0 #1< (0%K>#0% %O"#I;>%01E J(1#2% 15;1 ;2(::(0 <1);1%B? #< 1( ;)=#1);)#>? #0#1#;>#N% 15% ("1A"1 I;)#;=>% ;< (0% A(<<#=#>#1? ;0$ 25;0B% #1 $%A%0$#0B(0 15% )%<">1 (' 15% #' <1;1%:%01<L $(#0B <( %0<")% 15;1 ?(") ("1A"1 I;)#;=>% D#>> ;>D;?< =% $%'#0%$F15%)%=? )%$"2#0B 15% 25;02% (' ?(") 2($% A)($"2#0B ;0 %))()E

>-,53" >5(5#'#)51.

+D#125 <1;1%:%01< ;)% #' <1;1%:%01< 15;1 $%1%):#0% 15% ("1A"1 =;<%$ (0 15% I;>"% <1()%$ #0 ;defined variable. The terminology is slightly different for no necessary reason. “case” now replaces“elseif,” and “otherwise” replaces “else.” Once again, you can have as many cases as you want. The first>#0% ;>D;?< )%;$<“switch” followed by the name of the variable you are “switching” over.

Page 30: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 30/101

%?3;<> X4#-3#561W<#%1 X=.%%3561 4#6/1W

X<.01 56.<gW<#%1 X=.%%3561 4#6/1W

X<.01 56.<gW.;>1-?3%1

X<.01 56.<gW1$0

_() #0<1;02%F #' ?(" 5;I% ; <1)#0B <1()%$ #0 15% I;)#;=>%“str,” you can use a switch statement to outputD5%15%) #1 #< '(")F '#I%F () <#CE

%?3;<> $/Acase ‘four’

./; & HCcase ‘five’

./; & !Ccase ‘six’

./; & *C.;>1-?3%1

out = ‘Pharaoh’; 1$0

+%)#("<>?F '(>G<F 2(0$#1#(0;>< ;)% 15% %;<#%<1 15#0B #0 15% D()>$ 1( D)#1%E /' ?(" %02("01%) ;$#''#2">1 A)(=>%: #0I(>I#0B 2(0$#1#(0;><F 15% ;21";> $#''#2">1? D#>> 2(:% ')(: 15% (15%) %>%:%01< ;0$ 0(1')(: '():#0B 15% 2(0$#1#(0;>< 15%:<%>I%<E

Page 31: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 31/101

+%21#(0 +%I%03 /1%);1#(0

/1%);1#(0 #< ; ';02? 674879 D()$ '() >((A<F D5#25 #< ; ';02? 2(:A"1#0B D()$ '() )"00#0B ; <#0B>%2($% =>(2G :">1#A>% 1#:%<E 8((A< ;)% )%;<(0;=>? $#''#2">1 1( "0$%)<1;0$ =%2;"<%F "0>#G% :;0? (15%)2($#0B 1((><F 15%? ;)% 0(1 #01"#1#I%E P5%)%;< ?(" D(">$ 1%0$ 1( '(2"< (0 15% D5(>% A)(=>%: 1( '#0$ ;>><(>"1#(0< ;1 (02%F 674879 2;0 >((G ;1 %I%)? A(<<#=>% <(>"1#(0 #0$#I#$";>>?E

*(0<#$%) ; A)(=>%: ;<G#0B ?(" 1( <(>I% ; '(")15K()$%) A(>?0(:#;> %O";1#(0 '() ;>> )%;> N%)(<EQ0% ;AA)(;25 D(">$ =% 1( ;>B%=);#2;>>? () B);A5#2;>>? '#0$ 15% <(>"1#(0< U;>> ;1 (02%VL ;0(15%) ;AA)(;25D(">$ =% 1( 1)? A>"B 0":=%)< #01( 15% %O";1#(0 "01#> ?(" '#0$ ;>> '(") <(>"1#(0<E 8((A< ;>>(D ?(" 1(implement the latter method, typically called a “brute force” approach.

45%)% ;)% 1D( 1?A%< (' >((A<F '() >((A< ;0$ D5#>% >((A<E 4%250#2;>>?F '() >((A< ;)% "00%2%<<;)?=%2;"<% ;>> '() >((A< 2;0 =% )%D)#11%0 ;< D5#>% >((A<E i;);$(C#2;>>?F <1"$%01< ;>:(<1 0%I%) )%<()1 1(

"<#0B D5#>% >((A< =%2;"<% 15%? ;)% <>#B51>? :()% $#''#2">1 1( "0$%)<1;0$E

D&/ C&&21.

7>> '() >((A< ;)% D)#11%0 #0 15% '(>>(D#0B =;<#2 '():;13

2.- 3 & X41<;.-WX<.01 56.<gW

1$0

P5%0 674879 )%;25%< 15% >((AF #1 D#>> ;"1(:;1#2;>>? <%1 # %O";> 1( 15% '#)<1 I;>"% #0 15% I%21()F5%02%'()15 2;>>%$ 15% #1%);1#(0 A;);:;1%)E P5%0 #1 )%;25%< 15% %0$ (' 15% >((AFnamely the word “end”,674879 )%1")0< 1( 15% '#)<1 >#0% ;0$ 25;0B%< 15% I;>"% (' # 1( 15% 0%C1 I;>"% #0 15% I%21()E 45#< A)(2%<<2(01#0"%< "01#> 15%)% ;)% 0( I;>"%< )%:;#0#0B '() # 1( ;<<":%F ;1 D5#25 A(#01 674879 1%):#0;1%< 15%>((A ;0$ )%;$< 15% )%<1 (' ?(") 2($%E

e%1%):#0#0B 15% '#)<1 >#0% #< B%0%);>>? 15% :(<1 2(:A>#2;1%$ A;)1 (' D)#1#0B ; >((AE 45%A;);:%1%) ?(" <%1 $%1%):#0%< 5(D :;0? 1#:%< 15% >((A D#>> )"0E 45"<F 15% A)#:;)? $);D=;2G (' "<#0B'() >((A< #< 15;1 ?(" :"<1 =% ;=>% 1( A)%$%1%):#0% 5(D :;0? 1#:%< 1( #1%);1%E S(" D#>> B%0%);>>? "<% 15%I;)#;=>% # ;< ;0 #0$%C 15;1 25;0B%< '() %;25 #1%);1#(0E 45%)% ;)% 1D( =;<#2 <1);1%B#%<3

,E +%1 # %O";> 1( ; );0B% (' I;>"%< "<#0B 15% 2(>(0 (A%);1()E'() # h ,3,j'() # h ,3>%0B15UI;)#;=>%V

YE +%1 # %O";> 1( ; A)%$%1%):#0%$ () #0A"11%$ I%21()E i%(A>% "<";>>? '()B%1 15;1 15% I%21() 2;0=% 7JS4H/J!F 0(1 @"<1 ; );0B% (' I;>"%< D#15 <1%A <#N% ,E 674879 D#>> <1#>> #1%);1% ; 0":=%)(' 1#:%< %O";> 1( 15% >%0B15 (' 15% I%21()F ="1 # D#>> ;"1(:;1#2;>>? ;<<":% I;>"%< ')(: 15%

Page 32: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 32/101

I%21() #1<%>' );15%) 15;0 #0$#2%<E'() # h I%2

I always use the variable i when implementing for loops because that’s what my TA used.H(D%I%)F "<% D5;1%I%) I;)#;=>% <?<1%: :;G%< <%0<% 1( ?("E 45%? =%<1 D;? 1( >%;)0 >((A< #< =? >((G#0B

;1 %C;:A>%<E

P)#1% ; '"021#(0 <":X%2 15;1 1;G%< #0 ; I%21() ;0$ ("1A"1< 15% <": (' #1< %>%:%01< "<#0B #1%);1#(0E

2/$<;3.$ ./; & %/AV1< D41<I./; & OC2.- 3 & 8(61$@;>D41<I

./; & ./; 7 41<D3I1$0

1$0

H(D%I%)F 15#< <(>"1#(0 5;< ;0 "00%2%<<;)? 2(:A>#2;1#(0E / $%>#=%);1%>? #B0()%$ 15% :()% <%0<#=>%;AA)(;25 (' <#:A>? <%11#0B # %O";> 1( 15% I%21() #1<%>'E

2/$<;3.$ ./; & %/AV1< D41<I./; & OC2.- 3 & 41<

./; & ./; 7 31$0

1$0

P)#1% ; '"021#(0 2(:A;)%X%2 15;1 1;G%< 1D( I%21()< ;0$ ("1A"1< ; I%21() (' ;>> %>%:%01< 15;1 ;AA%;) #0=(15 I%21()< #0 15% <;:% A(<#1#(0 D#15 15% <;:% I;>"%E

70? A)(=>%: 15;1 ;<G< ?(" 1( ="#>$ ;0 ("1A"1 I%21() #0<#$% ; >((A D#>> 5;I% ; <(>"1#(0 #0 15% '(>>(D#0B'():;13

./; & PQC2.- 3 & X41<;.-W

32 X6.@3<#6 1'=-1%%3.$W./;D1$078I & X?>#;141- )./- ./;=/; %>./60 <.$;#3$W

1$01$0

45% #$%; #< 1( #0#1#;>#N% 15% ("1A"1 ;< ;0 %:A1? I%21() QM4+/eR 15% >((A ;0$ ="#>$ #1 %>%:%01K=?K%>%:%01 /J+/eR 15% >((AE 9? #0$%C#0B 15% I%21() ;1 A(<#1#(0 %0$T,F D% 2(01#0";>>? #02)%;<% 15% <#N% ('15% ("1A"1 I%21() =? ;$$#0B %>%:%01< (01( 15% %0$E 7 <#:A>% ;<<#B0:%01 <1;1%:%01 U("1 h #V D(">$(I%)D)#1% 15% 2"))%01 ("1A"1 I;)#;=>% %I%)? 1#:% 15% >((A #< )"0E a%1")0#0B 1( 15% 2(:A;)%X%2 A)(=>%:3

Page 33: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 33/101

2/$<;3.$ ./; & <.A=#-1V1< D41<8M 41<LI./; & PQC] & 61$@;>D41<8IC32 61$@;>D41<LI X 61$@;>D41<8I

] & 61$@;>D41<LIC1$0

h :1 A/%; 23-%; 01;1-A3$1 ;>1 61$@;> .2 ;>1 %>.-;1- 41<;.- %. ?1 g$.? >.?hA#$) ;3A1% ;. 3;1-#;1Bha/-;>1- 3;1-#;3.$ ?366 -1%/6; 3$ 3$01'3$@ ./;N.2N5./$0%B

2.- 3 & 8(]32 41<8D3I&&41<LD3I

./;D1$078I & 41<8D3ICh:1 <./60 #6%. ;#<g .$ 4#6/1% ;. ;>1 1$0 5) <.$<#;1$3$@ ;>1 </--1$; 41<;.-h?3;> ;>1 $1? 4#6/1Bh./; & P./;M 41<8D3IQC

1$01$0

1$0

8((A< A>;2%$ #0<#$% (15%) >((A< ;)% 2;>>%$ 0%<1%$ >((A<E J%<1#0B >((A< ;>>(D< ?(" 1( #1%);1% (I%):">1#A>% A;);:%1%)< <#:">1;0%("<>?E 7< ; '#0;> %C;:A>%F D% D#>> 2(0<#$%) ; 2;<% 15;1 2;00(1 =% <(>I%$D#15 (0>? ; <#0B>% >((AE

:-3;1 # 2/$<;3.$ <.A=S;- ;>#; ;#g1% 3$ ;?. %;-3$@% .2 1_/#6 61$@;> #$0-1;/-$% ;>1 6#-@1%; %1; .2 <.$%1</;341 61;;1-% ;>#; #==1#- 3$ 5.;> %;-3$@% #;;>1 %#A1 =.%3;3.$M 03%-1@#-03$@ <#%1B

compStr(‘henceforth, ‘heraldrth’) = ‘rth’

2/$<;3.$ ./; & <.A=S;-D%;-8M%;-LIout = ‘’;

%Once again we’re building an output element N5)N161A1$;M %. ?1 >#41 ;.3$3;3#63d1 3; jk[Sib, ;>1 6..=B

2.- 3 & 8(61$@;>D%;-8I2.- l & 3(61$@;>D%;-LI

hi2 l 3% 61%% ;>#$ 3M `f[]f\ ?366 ?#%;1 ;3A1 <.A=#-3$@ $.$1'3%;1$; -#$@1%63g1 %;-DH(FIB S3$<1 %;-8 #$0 %;-LhA/%; 51 .2 1_/#6 61$@;>M ?1 <./60 >#41 /%10 ;>1 61$@;> .2 %;-8 3$%;1#0B

32 %;-<A=3D%;-8D3(lIM %;-LD3(lII YY lN378 W 61$@;>D./;Ih:1 <.A=#-1 1#<> -#$@1 .2 4#6/1% 2-.A %;-8 ?3;> ;>1 1_/34#61$; -#$@1 2-.A%;-LB k$61%% ;>1 A#;<> 3%%longer than the ones we’ve already found, it is discounted.

./; & %;-8D3(lI1$0

1$0

Page 34: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 34/101

1$01$0

+",?# C&&21.

7>> D5#>% >((A< >((G >#G% 15#<3

?>361 X6.@3<#6 1'=-1%%3.$WX<.01 56.<gW

1$0

674879 '#)<1 %I;>";1%< 15% >(B#2;> %CA)%<<#(0 ;0$ )"0< 15% >((A "01#> 15% %CA)%<<#(0 =%2(:%<';><%E 45"<F ?(" :"<1 5;I% <(:%15#0B #0<#$% 15% >((A 15;1 25;0B%< 15% ("12(:% (' 15% >(B#2;>%CA)%<<#(0E Q15%)%D#<%F 674879 D#>> %01%) ;0 #0'#0#1% >((A 15;1 2;0 (0>? =% 1%):#0;1%$ "<#0B 2(01)(>T2E

7>15("B5 15%)% #< 0( #1%);1#(0 I;)#;=>% ;<<(2#;1%$ D#15 D5#>% >((A<F ;>> '() >((A< 2;0 =% )%D)#11%0;< D5#>% >((A< "<#0B ; 2("01%) I;)#;=>% #0<#$% 15%loop. The idea is to increase the counter’s value by oneeach time the loop is run. Let’s rewrite the sumVec function as a while loop.

2/$<;3.$ ./; & %/AV1< D41<I$/A & 8C./; & OC?>361 $/A X& 61$@;>D41<I

%Don’t forget to include the equals sign! ./; & ./; 7 41<D$/AIC$/A & $/A 7 8C

h[>3% 63$1 A.41% ;>1 ?>361 6..= ;.?#-0 ;>1 ;1-A3$#;3$@ <.$03;3.$B1$0

1$0

H(D%I%)F D5#>% >((A< ;)% "<";>>? "<%$ '() >((A< #0 D5#25 15% 0":=%) (' #1%);1#(0< #< #:A(<<#=>%1( %I;>";1% =%'()%5;0$E

P)#1% ; '"021#(0 !#$%(0 15;1 1;G%< #0 ; 0":=%)E /' 15% 0":=%) #< %I%0F $#I#$% #1 =? 1D(L #' #1 #< ($$F

:">1#A>? #1 =? 15)%% ;0$ <"=1);21 (0%E 45% '"021#(0 <5(">$ )%A%;1 15#< A)(2%<< "01#> 15% 0":=%) %O";><(0% U15#< ;>D;?< 5;AA%0<V ;0$ ("1A"1< 15% 0":=%) (' #1%);1#(0< )%O"#)%$E

2/$<;3.$ ./; & m301.$ D$/AI./; & 8C?>361 $/A e& 8

32 A.0D$/AMLI&&O$/A & $/AGLC

16%1

Page 35: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 35/101

$/A & $/AEF – 8C1$0./; & ./; 7 8C

1$01$0

In more colloquial terms, loops are “dead useful.” You can solve almost any problem with a well K#:A>%:%01%$ '() >((AE 6;G% <")% ?(" "0$%)<1;0$ >((A<F =%2;"<% ;>:(<1 %I%)? A)(=>%: ')(: 0(D (0D#>> #0I(>I% 15%:E

Page 36: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 36/101

+%21#(0 R#B513 *%>> 7));?<

*%>> ;));?< ;)% ;0(15%) $;1; 1?A% 674879 "1#>#N%< 1( <1()% #0'():;1#(0E e%<A#1% =%#0B#01#:#$;1#0B '() :(<1 A%(A>%F 2%>> ;));?< ;)% %;<? 1( D()G D#15 ;< >(0B ;< ?(" MJeRa+47Je D5;1 15%?are. Seriously, you don’t want to end up guessing when cell arrays appear on exams.

*%>> ;));?< ;)% ; "0#O"% $;1; 1?A% #0 15;1 15%? ;)% 2;A;=>% (' <1()#0B $;1; (' :">1#A>% (15%)1?A%<E R;25 %>%:%01 #0 ; 2%>> ;));? #< ; 2%>>F ;0$ ; 2%>> 2;0 2(01;#0 ;0?15#0B U$("=>%<F >(B#2;><F <1)#0B<F<1)"21")%<F () %I%0 (15%) 2%>><VE 6? <5()15;0$ '() ; 2%>> ;));? #< 2;E

%/#(5,): %#?? 9//(61.

*%>> ;));?< ;)% 2(>>%21#(0< %02>(<%$ #0 2")>? =);2G%1<E 45% (0>? $#''%)%02% #< 15;1 %>%:%01< 2;0

0(D =% (' ;0? $;1; 1?A%E 45#< #< 15% %;<? A;)1E

ca = { [1 2 3], ‘Judah’, [true true false] };

A)*#F,): %#?? 9//(61.

45% 2(:A>#2;1%$ 15#0B 2(02%)0#0B 2%>> ;));?< #< 15;1 15%? 2;0 =% #0$%C%$ #0 1)"% $#''%)%01 D;?<F"<#0B A;)%015%<%< UV () 2")>? =);2G%1< uvE /0$%C#0B D#15 A;)%015%<%< )%1")0< 15% ;21";> %>%:%01 U#0 ; ;));?F ; 2%>>VF D5%)%;< #0$%C#0B D#15 2")>? =);2G%1< )%1")0< 15% *QJ4RJ4+ (' 15% %>%:%01E /0 (15%)

D()$<F 2")>? =);2G%1< (A%0 ; 2%>> 1( $#<A>;? D5;1 #1 2(01;#0<L (0>? 2%>>< 2;0 =% #0$%C%$ D#15 2")>?=);2G%1<E

4( )%1")0 <A%2#'#2 2(:A(0%01< (' 15% 2(01%01< (' ; 2%>>F "<% 2")>? =);2G%1< 1( (A%0 15% 2%>>'(>>(D%$ =? A;)%015%<%< 1( #0$%C #1< 2(01%01<E P5%0 2%>>< ;)% 0%<1%$ #0<#$% %;25 (15%)F ?(" :"<1 "<%:">1#A>% <%1< (' 2")>? =);2G%1< 1( )%;25 D5;1%I%) #< ">1#:;1%>? #0<#$%E 45% )">%F D5#25 #< D%>> D()15:%:()#N#0BF #< 15;1 ?(" 2;0 (0>? #0$%C D#15 A;)%015%<%< (02%F ;0$ 15% A;)%015%<%< :"<1 2(:% >;<1 #0 ;<%1 (' #0$#2%<L 15#< :;G%< <%0<% #' ?(" A;"<% 1( 15#0G ;=("1 #1E

ca = {[true false], ‘Reuben’, {[1 2 3], ‘Gad’}}; <6#%%D<#I ans = ‘cell’

<6#%%D<#D8II ans = ‘cell’ <6#%%D<#n8oI ans = ‘logical’ <#DFI #$% & n8'L <166o<#nLo ans = ‘Reuben’ <#nLoDLI ans = ‘e’ <#nFon8oDFI #$% & F

Page 37: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 37/101

That’s pretty much #1 '() 2%>> ;));?<E a%:%:=%) 15;1 ?(" <1#>> "<% <O";)% =);2G%1<F 0(1 2")>?=);2G%1<F D5%0 2(02;1%0;1#0B ;0$ $%>%1#0B 2%>> ;));?<E 6(<1 (' :? %C;:A>%< D#>> #0I(>I% #01)#2;1%2(:=#0;1#(0< (' 2%>> ;));?< ;0$ >((A<E

P5%0 "<#0B 2%>> ;));?< ;0$ %<A%2#;>>? #1%);1#(0 ;0$ 2(0$#1#(0;><F #1 #< B%0%);>>? 0%2%<<;)? 1( G%%

1);2G (' $;1; 1?A%<E 45% '"021#(0< #<$("=>%UVF #<>(B#2;>UVF #<25;)UVF ;0$ #<2%>>UV )%1")0 ; >(B#2;> 1)"% ()(' D5%15%) 15% #0A"1 #< (' 15% <A%2#'#%$ $;1; 1?A%E 45% '"021#(0 #<%:A1?UV )%1")0< 1)"% #' 15% #0A"1 #< ;0%:A1? <1)#0BF I%21()F 2%>> ;));?F () <1)"21")% ;));?E

:-3;1 # 2/$<;3.$ `#$#%%1> ;>#; ;#g1% 3$ # <166 #--#) <.$;#3$3$@ 41<;.-% .21_/#6 61$@;> #$0 A1%>1% ;>1A ;.@1;>1- 3$;. .$1 6.$@ ./;=/; 41<;.-B [>1 23-%;161A1$; 3$ ;>1 ./;=/; 41<;.- %>./60 51 ;>1 23-%; 161A1$; .2 ;>1 23-%; 41<;.-M2.66.?10 5) ;>1 23-%; 161A1$; .2 ;>1 %1<.$0 41<;.-M #$0 %. .$B

`#$#%%1>DnP8 L FQ PH ! *Q P9 T UQoI #$% & P8 H 9 L ! T F * UQ

2/$<;3.$ ./; & `#$#%%1> D<#Ihp1->#=% ;>1 A.%; 3$;/3;341 ?#) ;. %.641 ;>3% =-.561A ?./60 51 ;. <-1#;1 #%3A=61 ;1%; <#%1 #$0 2.</% h.$ ;>1 301$;3;) .2 ;>1 ./;=/; 3$ -16#;3.$ ;. ;>13$=/;;10 <166 #--#)B a.- ;>1 <166 #--#) nP8 LQ PF HQ P! *QoMh;>1 ./;=/; 3% P<#n8oD8IM <#nLoD8IM <#nFoD8IM <#n8oDLIM <#nLoDLIM <#nFoDLIQBi; $.? 51<.A1% #==#-1$; ;>#; ;>1h23-%; 3$01' %;#-;% #; .$1 #$0 #==-.#<>1% ;>1 $/A51- .2 41<;.-%M #$0 ;>1%1<.$0 3$01' %;#-;% #; .$1 #$0h#==-.#<>1% ;>1 61$@;> .2 ;>1 41<;.-%B

./; & PQCh[>1 %.6/;3.$ 3% 01<1=;3416) %3A=61 5/; -1_/3-1% ;?. %3A/6;#$1./% 2.- 6..=%B

2.- 3 & 8(61$@;>D<#n8oIh[>1 ./;1- 6..= -/$% .$<1 2.- 141-) 161A1$; 3$ ;>1 41<;.-% D;>1 41<;.-% #-1#66 .2 1_/#6 61$@;>IB

2.- l & 8(61$@;>D<#Ih[>1 3$$1- 6..= -/$% .$<1 2.- 1#<> 41<;.- 3$ ;>1 <166 #--#)B

./;D1$078I & <#nloD3IC1$0

1$01$0

:-3;1 # 2/$<;3.$ `1=>35.%>1;> ;>#; ;#g1% 3$ # %;-3$@ #$0 034301% 3; 3$;.3$03430/#6 ?.-0%B [>1 2/$<;3.$ %>./60 ./;=/; # <166 #--#) <.$;#3$3$@ .$1 ?.-0=1- <166B

Mephibosheth(‘Jacob I have loved’) ans = {‘Jacob’ ‘I’ ‘have’ ‘loved’}

2/$<;3.$ ./; & `1=>35.%>1;> D%;-I./; & noC

Page 38: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 38/101

?>361 e3%1A=;)D%;-Ihi;1-#;1 /$;36 ;>1-1 3% $. %;-3$@ -1A#3$3$@B

[word, str] = strtok(str, ‘ ‘) h^1#%%3@$3$@ ;>1 4#6/1 .2 %;- A.41% /% ;.?#-0 ;>1 <.$03;3.$ ;>#; ;1-A3$#;1%;>1 6..=B

./;n1$078o & ?.-0C1$0

%You’ll be using this code t . 5-1#g 0.?$ ;1'; 2-.A $.;1=#0 2361% 3$ # 21??11g%B 1$0

Page 39: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 39/101

+%21#(0 J#0%3 H#B5K8%I%> _#>% /0A"1WQ"1A"1

_#>% #0A"1W("1A"1F 5%)%;'1%) )%'%))%$ 1( ;< '#>% /QF #< ; A)(2%<< =? D5#25 674879 2;0 )%;$$(2":%01< ')(: (15%) ')(: (15%) 2(:A"1%) A)(B);:<F :;0#A">;1% 15%:F ;0$ <;I% 15%: ;< 0%D$(2":%01< #0 ?(") 2"))%01 $#)%21()?E H#B5K>%I%> '#>% /Q <A%2#'#2;>>? #0I(>I%< $%;>#0B D#15 5#B5>? ()B;0#N%$;1; #0 0(1%A;$ ;0$ 6#2)(<('1 RC2%>E P% D#>> =% D()G#0B D#15 15)%% 1?A%< (' '#>%<3 2<I '#>%<F $>: '#>%<F ;0%C2%> <A)%;$<5%%1<E

45% A)#:;)? $#''#2">1? D#15 '#>% /Q #0I(>I%< 2(0I%)<#(0< =%1D%%0 $#''%)%01 $;1; 1?A%<E /' ?(" '#0$yourself using loops to accomplish simple conversions or comparisons, you’re probably doing somethingD)(0BE 45%)% ;)% ; '%D %;<? 1)#2G< 15;1 D#>> :;G% 15%<% A)(=>%:< :"25F :"25 %;<#%)E

M#(*,): ()* +/,5,): %>G D,?#1.

*+X <1;0$ '() 2(::;K<%A;);1%$ I;>"%<E 9;<#2;>>?F ; *+X '#>% #< ; J(1%A;$ E1C1 $(2":%012(01;#0#0B (0>? ;0 ;));? (' 0":=%)< <%A;);1%$ =? 2(::;<E 70? <A;2%< ;0$ %:A1? >#0%< #0 15% '#>% ;)%2(:A>%1%>? #B0()%$E /' 15% $(2":%01 2(01;#0< ;0?15#0B (15%) 15;0 $("=>%< U0%B;1#I% 0":=%)< ;0$');21#(0< ;)% (G;?V ;0$ 2(::;<F #1 #< 0(1 ; *+X '#>%E 45%)% ;)% 1D( '"021#(0< ?(" 0%%$ 1( G0(DE

;)) h 2<I)%;$U'#>%0;:%V

45% '"021#(0 2<I)%;$UV 1;G%< #0 15% '#>%0;:% U;>D;?< ; <1)#0BV (' ; E1C1 *+X '#>% #0 ?(") 2"))%01$#)%21()?F )%:(I%< 15% 2(::;<F ;0$ ("1A"1< 15% )%<">1#0B ;));? (' $("=>%<E /' 15% ;));? #< 0(1)%21;0B">;)F #1 '#>>< ;0? "0"<%$ <A;2% D#15 N%)(<E

_() %C;:A>%F 2<I)%;$ D#>> 1")0 15% '(>>(D#0B '#>% #01( 15% )%<">1;01 ;));?3

1 2 34 5 67 0 0

<%4?-3;1D2361$#A1M #--#)I

45% (15%) <#B0#'#2;01 '"021#(0 #< 2<ID)#1%UVF D5#25 $(%< %C;21>? 15% (AA(<#1%E /1 1;G%< #0 ;0 ;));?(' $("=>%< ;0$ <;I%< 15% 2())%<A(0$#0B *+X $(2":%01 ;< ; '#>% #0 ?(") 2"))%01 $#)%21()?E i>%;<% 0(1%15;1 2<ID)#1%UVF ;0$ ;0? D)#1#0B '"021#(0 '() 15;1 :;11%)F $(%< 0(1 5;I% ;0? ("1A"1L ?(" <5(">$ 0(1<"AA)%<< #1 D#15 ; <%:#2(>(0 () <%1 #1 %O";> 1( ;0?15#0BE

M#(*,): ()* +/,5,): 8CB D,?#1.

,FYF-ZF`Fb.

Page 40: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 40/101

7 $>: '#>% #< %C;21>? 15% <;:% ;< ; 2<I '#>% %C2%A1 15;1 15% $("=>%< 2;0 =% <%A;);1%$ =? ;0?$%>#:#1%) );15%) 15;0 @"<1 2(::;<E e%>#:#1%)< 2;0 =% 25;);21%)< <"25 ;< %C2>;:;1#(0 A(#01<F >%11%)<F ()%I%0 0":=%)<E a%:%:=%) 15;1 15% $%>#:#1%) #< ;>D;?< 2(0<#$%)%$ ; <1)#0B %I%0 #' #1 #< ; 0":=%)E Q02%;B;#0F 15%)% ;)% 1D( '"021#(0 ?(" 0%%$ 1( G0(D3

#-- & 06A-1#0D2361$#A1M 0163A3;1-I

M0>#G% D#15 2<I '#>%<F 674879 $(%< 0(1 ;"1(:;1#2;>>? G0(D D5;1 25;);21%) #< =%#0B "<%$ ;< 15%$%>#:#1%) #0 ; 1%C1 '#>%L ?(" D#>> 15%)%'()% 0%%$ 1( <A%2#'? 15% $%>#:#1%) #0 <1)#0B '():;1 ;< ; <%2(0$ #0A"If you don’t feel like including the second input, MATLAB will attempt to guess the delimiter for you; it>#G%< 1( 25((<% 15#0B< >#G% 2(::;< ;0$ <A;2%<E S(" 2;0 ;><( D)#1% $%>#:#1%$ '#>%< @"<1 >#G% 2<I '#>%<L 15(0>? $#''%)%02% #< 15;1 ?(" :"<1 0(D <A%2#'? 15% $%>#:#1%) ?(" D;01 674879 1( "<%E

06A?-3;1D2361$#A1M #--#)M 016A3;1-I

M#(*,): ()* +/,5,): EF3#? >2/#(*1"##51.

i%'():#0B 1;<G< (0 %C2%> <A)%;$<5%%1< #< %;<#>? 15% :(<1 "<%'"> ;AA>#2;1#(0 (' 5#B5 >%I%> '#>% /QFD5#25 #< D5? :(<1 5(:%D()G ;0$ 1%<1 A)(=>%:< '(2"< (0 15#< 1(A#2 <A%2#'#2;>>?E

P$/AM ;1';M -#?Q & '6%-1#0D2361$#A1I

45% '"021#(0 1( )%;$ #0 %C2%> $(2":%01< 5;< 15)%% ("1A"1< #0<1%;$ (' (0%E 7>15("B5 15% 0;:%<?(" ;<<#B0 15%: $( 0(1 :;11%)F 15% <1;0$;)$ 2(0I%01#(0 #0 *+ ,-., #< 1( "<% 15% 0;:%< 0":F 1%C1F ;0$);DE Q=I#("<>?F 674879 D#>> ;>D;?< A)($"2% 15% <;:% ("1A"1< #0 15% <;:% ()$%)F <( G0(D#0B 15% ()$%)(' 15% ("1A"1< #< I%)? #:A()1;01E

45% '#)<1 ("A1"1F 0":F '#0$< ;>> 2%>>< #0 15% <A)%;$<5%%1 15;1 2(01;#0 0":=%)< ;0$ 1")0< 15%:#01( ;0 ;));? (' $("=>%<F :"25 >#G% 2<I)%;$UVE 674879 '#0$< 15% <:;>>%<1 )%21;0B>% (' 2%>>< 15;1 #02>"$%<;>> 0":=%)< #0 15% <A)%;$<5%11 ;0$ '():< 15%: #01( ;0 ;));?E /' ;0? 2%>>< #0 15% )%21;0B>% 2(01;#0 0(0Knumbers or are empty, MATLAB pads the empty space with NaN, which stands for “Not a Number.”

45% <%(0$ ("1A"1F 1%C1F '#0$< ;>> 15% D()$< U0(0K0":=%)<V #0 15% <A)%;$<5%%1 ;0$ '():;1< 15%:#01( ; 2%>> ;));? (' <1)#0B< #0 15% <;:% D;?F 2)%;1#0B 15% <:;>>%<1 )%21;0B>% A(<<#=>%E R:A1? 2%>>< ;0$ 2%>2(01;#0#0B 0":=%)< ;)% A;$$%$ D#15 %:A1? <1)#0B<E

45% 15#)$ ("1A"1F );DF 1;G%< 15% %01#)% <A)%;<5%%1 ;0$ 1")0< #1 #01( ; 2%>> ;));?E R:A1? <A;2%< ;)%

A;$$%$ D#15 2%>>< 2(01;#0#0B J;JE

45% :(<1 #:A()1;01 15#0B< 1( )%:%:=%) ;)% 15% )%<A%21#I% $;1; 1?A%< (' 15% 15)%% ("1A"1<EJ": #< ;0 ;));? (' $("=>%<F D5%)%;< 1%C1 ;0$ );D ;)% =(15 2%>> ;));?<E P5%0 A%)'():#0B 0":%)#2;>2;>2">;1#(0<F #1 #< ('1%0 %;<#%) 1( "<% 0":L 15% $);D=;2G #< 15;1 0": #< 0(1 0%2%<<;)#>? 15% <;:% <#N% ;<15% <A)%;$<5%%1 #1<%>'E a;D #< =? $%'#0#1#(0 15% <;:% <#N% ="1 2;))#%< 15% $);D=;2G (' =%#0B ; 2%>> ;));?EP5%0 <(>I#0B A)(=>%:<F 25((<% D5#25%I%) ("1A"1 <%%:< %;<#%<1 '() ?("E

Page 41: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 41/101

Given the spreadsheet “people.xls”

[num, text, raw] = xlsread(‘people.xls’)

$/A & 192020

;1'; &

′ ′

′ ′

′ ′

′ ′

′ ′

′′

′′

′′

′ ′

′ ′

′ ′

′ ′

-#? &

′ ′ ′ ′ ′ ′

′ ′ [19] ′ ′

′ ′

′ ′ [20][20] ′ ′

′ ′

S(" 2;0 ;><( D)#1% ;));?< ;0$ 2%>> ;));?< #01( %C2%> <A)%;$<5%%1<E 45% '"021#(0 0;:% #< A)%11?(=I#("<E

'6%?-3;1D2361$#A1M #--I

And that’s basically it for high level file IO. I’ll quickly recap the si C '"021#(0< =%'()% :(I#0B (01(%C;:A>% A)(=>%:<E

#-- & <%4-1#0D2361$#A1I<%4?-3;1D2361$#A1M #--I#-- & 06A-1#0D2361$#A1M 0163A3;1-I06A?-3;1D2361$#A1M #--M 0163A3;1-IP$/AM ;1';M -#?Q & '6%-1#0D2361$#A1I'6%?-3;1D2361$#A1M #--I

P)#1% ; '"021#(0 H;BB;# 15;1 1;G%< #0 15% 0;:% (';0 %C2%> $(2":%01 2(01;#0#0B #0'():;1#(0 ;=("1 ;'((1);2% #0 15% '(>>(D#0B '():;1E 45% $(2":%01 :;? 5;I% ;0? 0":=%) (' )(D< ="1 D#>> ;>D;?< 2(01;#0

Page 42: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 42/101

15)%% 2(>":0< D#15 15% '(>>(D#0B 2(>":0 5%;$%)<3

45% '"021#(0 <5(">$ )%;$ #0 15% <A)%adsheet and add an additional column called “Result” as the fourth2(>":0E 45#< 2(>":0 2(01;#0< 15% '#0;> A(<#1#(0 (' %;25 2(:A%1#1() =;<%$ (0 5#< 1(1;> 1#:%E 45% '"021#(0<5(">$ ;><( ;$$ ;0 ;$$#1#(0;> )(D 1( 15% %0$ (' 15% <A)%;$<5%%1E 45% '#)<1 2(>":0 #0 15#< )(D D#>> =% 15%

string “Fastest Lap”, and the second column will contain the overall fastest lap in the race. The function<5(">$ D)#1% 15% )%<">1;01 2%>> ;));? 1( ;0 %C2%> '#>%E 45% '#>%0;:% <5(">$ =% 15% #0A"1 '#>%0;:% D#15“_edited” appended to th % %0$E 45% '#0;> ("1A"1 D#>> >((G >#G%3

2/$<;3.$ q#@@#3D2$I P$/AM eM -#?Q & '6%-1#0D2$IC

h ^1#03$@ 3$ ;>1 2361 3% /%/#66) ;>1 23-%; %;1=B ;.;#6% & $/AD(M1$0IC

%For the first step, we’re only interested in the total time of eachh<.A=1;3;.-B [>3% 3% # -#<1M %. 6.?1- % total times will receive lower position numbers. To achieve this, we’ll useh;>1 %1<.$0 ./;=/; .2 ;>1 h%.-;DI 2/$<;3.$M ?>3<> 3% ;>1 3$03<1% /%10 ;. %.-; ;>1 3$=/;B

PeM -#$gQ & %.-;D;.;#6%IC hk$2.-;/$#;16)M # %3A=61 %.-;3$@ A1;>. d doesn’t quite work with rankingh=1.=61M %. ?1 >#41 ;. <#66 ;>1 %sort function AGAIN on the indices. I’ll overwrite both variables from the%previous function since we %won’t be using them anymore.

Page 43: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 43/101

PeM -#$gQ & %.-;D-#$gIC hR.? ?1 >#41 # <.6/A$ 41<;.- <#6610 3$01' ;>#; <.$;#3$% ;>1 23$#6 -#$g .2h1#<> <.A=1;3;.-B [. h<.$<#;1$#;1 ;>3% .$;. ;>1 -#? %=-1#0%>11; 0#;#M ?1 >#41 ;. <.$41-; 3; ;.h;)=1 <166B h3$01' & n3$01'o ?366 =/; ;>1 1$;3-1 41<;.- 3$%301 # SiRm], <166M ?>3<> 3%h/$2.-;/$#;16) $.; ?>#; ?1 ?#$;B h:1 $110 ;. <-1#;1 # 41<;.- .2 <166%M 1#<> <.$;#3$3$@ .$1 $/A51- 2-.A ./-h3$01' 41<;.-B ]/<g36)M %there’s a MATLAB function that does just that.

-#$g & $/AL<166D-#$gIC %Now we need to concatenate rank onto the string ‘Result’. Since we’re<.$<#;1$#;3$@ <166%M 5.;>h161A1$;% A/%; 51 .2 ;)=1 <166B :1 ;>1-12.-1 1$<6.%1 ;>1 %;-3$@ 3$ </-6)5-#<g1;% 512.-1 <.$<#;1$#;3$@B

<.6/A$ & Pn r^1%/6;r oC -#$gQC %We’re finished with ;>1 6#%; <.6/A$M %. ?1 <#$ #00 3; .$;. ;>1 -#?h%=-1#0%>11; 0#;#B

-#? & P-#?M <.6/A$QC hR.? ?1 l/%; >#41 ;. 01;1-A3$1 ;>1 2#%;1%; 6#= #$0 =1-2.-A ;>1 %#A1

%algorithm. Remember that we’re h#003$@ # -.? 3$%;1#0 .2 # <.6/A$M %. >.-3d.$;#6 #$0 41-;3<#6 <.$<#;1$#;3.$%h?366 51 -141-%10B

2#%;1%;K6#= & A3$D$/AD(M8IIC %We can’t concatenate this time because the dimensions are not consistent, so%we’ll use MATLAB’s h3$01'3$@ ./; .2 5./$0% ;-3<gB `f[]f\ ?366 =#0 ;>1 -1A#3$3$@ %=#<1% ?3;>h1A=;) <166%B

-#?D1$078M8I & n ra#%;1%; ]#=r oC -#?D1$0MLI & n2#%;1%;K6#=oC

hR.? #66 ?1 >#41 ;. ?.--) #5./; 3% ?-3;3$@ ;>1 #--#) ;. ;>1 <.--1<; 2361$#A1BhS3A=6) #==1$03$@ %”_edited” onto the end will produce something like “race.xls_edited”, whichh3% $.; # 4#630 2361$#A1B %The “.xls” part must come last. There are probably a dozen ways to do this.%Here’s an elegant one.

2$L & %=-3$;2D rh%K103;10B'6%r M %;-;.gD2$M rBr IIC hs./ <#$ #6%. /%1 23$0DI ;. 6.<#;1 ;>1 =1-3.0B

'6%?-3;1D2$LM -#?I 1$0

<1#J7? D7)35,&)1.

0":Y2%>>U;))V—2(0I%)1< ;0 ;));? (' $("=>%< #01( ; 2%>> ;));? D5%)% %;25 2%>> 2(01;#0< (0%$("=>%

2%>>Y:;1U2;V—2(0I%)1< ;0 ;));? (' 2%>>< 2(01;#0#0B $("=>%< #01( ;0 ;));? (' $("=>%< k<()1F #0$%Cl h <()1UI%2V—;>D;?< #:A()1;01 '() <()1#0B

Page 44: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 44/101

Page 45: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 45/101

%01#)%>? 0%D =>;0G $(2":%01E /' ?(" <A%2#'? 15% D)#1% A%):#<<#(0 ;0$ 15% '#>%0;:% $(%< 0(1 %C#<1 #0 ?(")2"))%01 $#)%21()?F 674879 D#>> ;"1(1:;1#2;>>? 2)%;1% ; =>;0G 0(1%A;$ '#>% ;>(0B D#15 #1< )%<A%21#I% '#>%5;0$>%E 45% ;AA%0$ A%):#<<#(0 ;>>(D< ?(" 1( ;$$ :()% #0'():;1#(0 (01( 15% %0$ (' ;0 %C#<1#0B '#>%EFortunately, you’ll probably never be appending anything in this class, so don’t worry about it.

45%)% #< (0% #01%)%<1#0B %))() ?(" :;? %02("01%) D5%0 "<#0B '(A%0UVE /' ; 2;>> 1( 15% '#>% 5;0$>%later in your script produces an error like “Error using fgetl: invalid file identifier”, fopen() probably failed1( (A%0 15% #0A"1 '#>%E 45#< 1%0$< 1( 5;AA%0 (0>? D5%0 "<#0B 15% D)#1% A%):#<<#(0 1( 2)%;1% ; 0%D '#>%;0$ #< 2;"<%$ =? <(:% <()1 (' 674879 A%):#<<#(0 %))()E 674879 D#>> 2(01#0"% )%;$#0B ?(") 2($% ="1D#>> <%1 15% '#>% 5;0$>% %O";> 1( K, 1( #0$#2;1% ; ';#>")% #0 (A%0#0B 15% '#>%E /' ?(" %02("01%) 15#< %))()F25;0B% ?(") 2"))%01 $#)%21()? 1( <(:%15#0B %><% ;0$ 15%0 25;0B% #1 =;2GL 15#< D#ll reset MATLAB’sA%):#<<#(0<E

fh = fopen(fn, ‘r’) fh = fopen(fn, ‘w’) fh = fopen(fn, ‘a’)

D:#5?HI ()* D:#51HI

7< / <1;1%$ %;)>#%)F 15% '#>% 5;0$>% #< ;21";>>? )%>;1#I%>? "<%>%<<L ?(" 0%%$ ; $#''%)%01 '"021#(0 1:(I% 15)("B5 15% $(2":%01 ;0$ 1;G% ("1 %;25 >#0%E 45% 'B%1>UV ;0$ 'B%1<UV '"021#(0 )%1")0 15% >#0% 15%file handle is currently pointing to, although in slightly different ways. Please note my shortand “line” to)%A)%<%01 ; >#0% (' 1%C1E

63$1 & 2@1;6D2>I

63$1 & 2@1;%D2>I

45%<% 1D( '"021#(0< ("1A"1 15% 2"))%01 >#0% UD5#25%I%) (0% 15% '#>% 5;0$>% #< A(#01#0B 1(V ;< ;<1)#0BE R;25 1#:% ?(" 2;>> %#15%) (' 15%<% '"021#(0<F 15% '#>% 5;0$>% :(I%< $(D0 1( 15% 0%C1 >#0% #0 15%$(2":%01F <( ?(" 2;0 ;21";>>? :(I% 15)("B5 15% %01#)% $(2":%01 <#:A>? =? )"00#0B 15% <;:% >#0% ('2($% (I%) ;0$ (I%)E

9%2;"<% (' 15#< ';21F ; <#:A>% D5#>% >((A 2(">$ %;<#>? A">> ("1 %I%)? >#0% ')(: ; A;)1#2">;)$(2":%01E P5%0 15% '#>% 5;0$>% 5;< :(I%$ $(D0 ';) %0("B5 15;1 15%)% ;)% 0( 0%D >#0%< )%:;#0#0B #015% $(2":%01F 'B%1>UV ;0$ 'B%1<UV ("1A"1 ; K, #0<1%;$ (' ; >#0%E 9%2;"<% 15#< K, #< ; $("=>% );15%) 15;0 ;<1)#0BF ?(" 2;0 <%1 ?(") D5#>% >((A 1( )"0 ;< >(0B ;< 15% 2"))%01 >#0% #< (' 1?A% 25;)E

?>361 3%<>#-D63$1IX<.01 56.<gW

1$0

45%)% #< (0>? (0% 0(1#2%;=>% $#''%)%02% =%1D%%0 'B%1>UV ;0$ 'B%1<UVE R;25 >#0% (' 1%C1 #0 ;$(2":%01 %0$< D#15 ; 0%D >#0% 25;);21%)3 w0E 45#< <?:=(> 1%>>< 2(:A"1%) A)(B);:< 1( <G#A 1( 15% 0%C1

Page 46: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 46/101

line on the page before continuing. Although the new line character is usually invisible (it’s not really 1%C1VF #1 #< #05%)%01>? 15%)%E

_B%1>UV )%:(I%< 15% 0%D >#0% 25;);21%) ')(: 15% ("1A"1 ;0$ )%1")0< (0>? 15% )%>%I;01 1%C1 ;< ;25;);21%) <1)#0BE _B%1<UV )%1")0< 15% %01#)% >#0% #02>"$#0B 15% 0%D >#0% 25;);21%)E _B%1>UV #< :()% "

?(" ;)% (0>? 2(02%)0%$ D#15 #01%)A)%1#0B $;1; #0 ; 0(1%A;$ '#>%L 'B%1<UV #< :()% "<%'"> D5%0 ?(" ;)%2(A?#0B $;1; 1( ; $#''%)%01 '#>% =%2;"<% #1 ;"1(:;1#2;>>? 2(A#%< 0%D >#0% 25;);21%)< ;< D%>>E

D2/,)5JHI

45% 'A)#01'UV '"021#(0 ;>>(D< ?(" 1( A)#01 1%C1 1( 15% 2(::;0$ <2)%%0 () ; 0(1%A;$ '#>%E 45%D()$ A)#01 :;? =% 2(0'"<#0B #' ?(" ;)% "0"<%$ 1( #1E 4( <%% ;0 %C;:A>% (' A)#01%$ 1%C1F 1?A% ; >#0% ('code without suppressing the output; the result of your code will be “printed” in the command window._A)#01'UV $(%< 0(1 5;I% ;0 ("1A"1E

fprintf(filename, str, var1, var2,…)

8#G% <A)#01'UVF 'A)#01'UV 2;0 =% "<%$ 1( A)#01 '():;11%$ <1)#0B<F () <1)#0B< 2(01;#0#0B I;)#;=>%<ESimply replace the doubles and strings in the formatted string with %d and %s, respectively. If you don’t<A%2#'? 15% '#>% 5;0$>% (' 15% $(2":%01 ?(" D#<5 1( A)#01 1(F 674879 D#>> A)#01 1( 15% 2(::;0$window. To utilize tabs and new lines, print ‘ wt’ and ‘ wn’, respectively.

In the following examples, we’re printing to a notepad file called “Rahab.txt”.

2> & fopen(‘Rahab.txt’, ‘w’) fprintf(fh, ‘%s’, ‘Mordecai’) prints ‘Mordecai’

fprintf(fh, ‘%s t n’, ‘Mordecai’) prints ‘Mordecai’ and new line character fprintf(fh, ‘ t n’) =-3$;% $1? 63$1 <>#-#<;1-

>5/5&0 C&&21

_#>% /Q 2($#0B A)(=>%:< ')%O"%01>? %01;#> ;0;>?N#0B %I%)? #0$#I#$";> D()$ (' ; $(2":%01E 45#<1;<G #< :(<1 %;<#>? ;22(:A>#<5%$ "<#0B <1)1(GUV ;0$ ; D5#>% >((AF D#15 ; <A;2% ;< 15% $%>#:#1%)E 45% >((A<5(">$ 2(01#0"% "01#> 15% )%:;#0$%) (' 15% <1)#0BF 15% <%2(0$ ("1A"1 (' <1)1(GUVF 0( >(0B%) 2(01;#0<;0?15#0BE

line = ‘Jeroboam’ ?>361 e3%1A=;)D63$1I

[word, line] = strtok(line, ‘ ‘) X<.01 56.<gW

1$0

Page 47: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 47/101

Initializing “line” is perhaps the easier method to understand. The other option is to actually run<1)1(GUV () 'B%1>UV =%'()% %01%)#0B 15% )%<A%21#I% D5#>% >((p. Note also that overwriting “line” instead of"<#0B ; $#''%)%01 I;)#;=>% 0;:% ;>>(D< "< 1( )%$"2% (") 0":=%) (' <1)1(GUV 2;>>< =? (0%E

C&&2@()*@(@4(?J.

e%A%0$#0B (0 5(D ?(" <1)"21")% ?(") D5#>% >((A<F #1 :;? =% 0%2%<<;)? 1( #:A>%:%01 ; >((AK;0$K;K5;>' ;1 <(:% A(#01E *%)1;#0 A)(=>%:< 2;0 (22") #' 15% 1%):#0;1#0B 2(0$#1#(0 5;< =%%0 :%1 D5#>%?(" <1#>> 5;I% $;1; >%'1 1( "<%E /0F #0 (") ;=(I% %C;:A>% D#15 <1)1(GUVF D% $%2#$%$ 1( 5;I% 15% 2($% =>(2G79QXR 15% <1)1(G 2;>>F 674879 D(">$ A">> ("1 15% '#0;> D()d of the line (making “rest” empty) and fail to)%%01%) 15% >((AE 7$$#0B ; <#:A>% 2(0$#1#(0;> <1;1%:%01 '#C%< 15#< A)(=>%:E

line = ‘Jeroboam’ ?>361 e3%1A=;)D63$1I

X<.01 56.<gWP?.-0M 63$1Q & %;-;.gD63$1I32 3%1A=;)D63$1I

X<.01 56.<gW1$0

1$0

D3?&1#HI

The fclose() function closes documents you’ve opened. Having a bunch of extraneous

$(2":%01< (A%0 D#>> 1%0$ 1( <>(D $(D0 674879 ;0$ #< 2(0<#$%)%$ <>(AA? U15;1 :%;0< ?(" >(<% A(#01<VE_2>(<%UV $(%< 0(1 5;I% ;0 ("1A"1E

'2>(<%U'5V

_2>(<%UV #< %;<? 1( "<% ;0$ %I%0 1( '()B%1 ;=("1E a%:%:=%)F '2>(<%UV #< ;>D;?< 2;>>%$ (0 15% '#>%handle, not the filename; this is a very common mistake. Let’s work an example problem to see how all15%<% %>%:%01< 2(:=#0%E

:-3;1 # 2/$<;3.$ ,63%># ;>#; ;#g1% 3$ ;>1 2361$#A1 .2 # B;'; 0.</A1$;B[>1 2/$<;3.$ %>./60 ./;=/; ;>1 $/A51- .2 ?.-0% 3$ ;>1 0.</A1$;D#$);>3$@ %1=#-#;10 5) %=#<1% <./$;% #% # ?.-0IB [>1 3$=/; 2361<.$;#3$% # %=#<1 #2;1- ;>1 6#%; ?.-0 .2 1#<> 63$1B ,63%># %>./60<-1#;1 # $1? 2361 ?3;> ;>1%1 1';-#$1./% %=#<1% -1A.410B [>1 2361$#A1.2 ;>3% $1? 2361 %>./60 51 ;>1 .-3@$3$#6 2361$#A1 2.66.?10 5)“_edited”.

2/$<;3.$ $/A & ,63%>#D2$I

Page 48: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 48/101

Page 49: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 49/101

+%21#(0 ,,3 +1)"21")% 7));?<

_() :(<1 A%(A>%F <1)"21")%< 2(0<1#1"1% 15% :(<1 $#''#2">1 674879 2(02%A1E +1)"21")%< ;0$<1)"21")% ;));?< ;)% :%)%>? ;0(15%) "<%'"> :%15($ '() ()B;0#N#0B #0'():;1#(0E 6"25 >#G% 2%>> ;));?<F<1)"21")% ;));?< 2;0 =% (' ;0? >%0B15 ;0$ ;)% 2;A;=>% (' <1()#0B %I%)? $;1; 1?A%F #02>"$#0B (15%)<1)"21")%<E

7 <1)"21")% #< =;<#2;>>? ; >#<1 (' #0'():;1#(0 <1()%$ #0 $#''%)%01 5%;$#0B<F 1%):%$ '#%>$<E R;25 '#%>$#< ; <1)#0B 2;A;=>% (' <1()#0B (0% A#%2% (' #0'():;1#(0 U$("=>%F >(B#2;>F <1)#0BF 2%>>F <1)"21")%F %12EV A%<1)"21")%E _#%>$0;:%< ;)% 2;<%K<%0<#1#I%F @"<1 >#G% %I%)?15#0B %><%E

%/#(5,): >5/7357/#1 B()7(??6.

45%)% ;)% 1D( :%15($< '() 2)%;1#0B <1)"21")%<E 45% '#)<1 #< 1( ;<<#B0 %;25 $;1": :;0";>>? "<#0B15% $(1 UEV (A%);1()E +1)"21")% ;<<#B0:%01< )%O"#)% 15)%% #0A"1<3 15% 0;:% (' 15% <1)"21")%F ; '#%>$0;:%F;0$ <(:%15#0B 1( ;<<#B0 1( #1F ()B;0#N%$ #0 15% '(>>(D#0B ';<5#(0 "<#0B 15% $(1E

%;-/<;/-1B23160 & %.A1;>3$@

/' 15% <1)"21")% $(%< 0(1 ;>)%;$? %C#<1F 674879 ;"1(:;1#2;>>? 2)%;1%< (0% ;0$ <1()%< #1 #0 ?(")2"))%01 D()G<A;2%E /' 15% '#%>$ $(%< 0(1 ;>)%;$? %C#<1F 674879 ;"1(:;1#2;>>? ;$$< #1 1( 15% )%<A%21#I%<1)"21")% =%>(D ;0? '#%>$< ;>)%;$? A)%<%01E Q15%)D#<%F 15% <1)"21")% #< "A$;1%$ 1( #02>"$% D5;1%I%) 0%information you’re storing in it.

6? <5()15;0$ '() <1)"2 tures is “sa”, standing for “structure array.”

%#B$#A1 & ru143$rC%#B#@1 & 8UC%#&name:’Kevin #@1(8U

/0$#I#$";> <1)"21")%< 2;0 =% 2(02;1%0;1%$ #0 )(D< ;0$ 2(>":0< @"<1 >#G% ;));?< (' $("=>%<U5(:%D()G ;0$ 1%<1 A)(=>%:< 0%I%) <%%: 1( :(I% =%?(0$ <1)"21")% I%21()<F '()1"0;1%>?VE 4( 2)%;1% ;<%2(0$ <1)"21")% "0$%) 15% <;:% I;)#;=>% 0;:%F <#:A>? ;$$ #1< A(<#1#(0 0":=%) #0 A;)%015%<%< =%'()%15% $(1E

%#D'IB23160 & %.A1;>3$@

f"<1 >#G% D#15 I%21()<F ?(" "<% 15% $(1 ;<<#B0:%01 1( #0$%C ("1 (' =("0$<E 674879 D#>>;"1(:;1#2;>>? '#>> ;0? #0K=%1D%%0 <A;2% D#15 "0;<<#B0%$ '#%>$< ;0$ <1)"21")%< D#15 %:A1? I%21()<E

Page 50: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 50/101

+#:#>;)>?F ;$$#0B ;0 ;$$#1#(0;> '#%>$ 1( (0% <1)"21")% D#>> ;><( ;$$ #1 1( %I%)? (15%) (0%F D#15 ;0%:A1? I%21() '() ;0? "0;<<#B0%$ '#%>$<E

sa(2).name = ‘Micah’; %#D8I & %#DLI &Name:’Kevin’ Name:’Micah’ f@1(8U f@1(PQ

S(" D#>> ')%O"%01>? %02("01%) <#1";1#(0< D5%)% 15% '#%>$0;:% ?(" D#<5 1( 2)%;1% () ;22%<< #< 0(1B#I%0 ="1 <1()%$ ;< ; <1)#0B #0 (0% (' ?(") I;)#;=>%<E /0 15;1 2;<%F ?(" 2;0 %02>(<% 15% I;)#;=>% )%'%))#0B1( 15% '#%>$0;:% #0 A;)%015%<%<L 674879 #01%)A)%1< #1%:< #0 A;)%015%<%< ;< I;)#;=>% 0;:%< );15%) 15;0$#)%21 '#%>$0;:%<E

Joseph = ‘Age’; %#Bv.%1=> & 8U%# &v.%1=>( 8U

%#LBDv.%1=>I & 8U%#L &f@1( 8U

*)%;1#0B <1)"21")%< :;0";>>? #< %;<? 1( )%:%:=%) ;0$ #:A>%:%01F <( 15%)% (=I#("<>? :"<1 =% ;:()% 2(:A>#2;1%$ :%15($ "<%$ 1( 1():%01 <1"$%01< (0 1%<1<E 45;1 :%15($ #< 2;>>%$ 15% <1)"21UV'"021#(0E

>5/735HI.

R01#)% <1)"21")% ;));?< 2;0 =% 2)%;1%$ #0 ; <#0B>% >#0% (' 2($% I#; 15% <1)"21UV '"021#(0E /1 1;G%< #0;0? 0":=%) (' #0A"1 '#%>$0;:%< ;0$ 2%>> ;));?< (' $;1; ;0$ 2)%;1%< 15% 2())%<A(0$#0B <1)"21")%E

sa = struct(‘field1’, {…}, ‘field2’, {…}, …)

45% 0":=%) (' <1)"21")%< #0 15% )%<">1;01 ;));? #< ;>D;?< %O";> 1( 15% >%0B15 (' 15% #0A"1 2%>>;));?<E 45% '#)<1 <1)"21")% D#>> 2(01;#0 ;>> (' 15% '#%>$0;:%< U15% ($$K0":=%)%$ #0A"1<V ;0$ 15% '#)<1%>%:%01 (' %;25 2%>> ;));? U15% %I%0K0":=%)%$ #0A"1<VE 45% <%2(0$ <1)"21")% D#>> 2(01;#0 ;>> '#%>$0;:%<;0$ 15% <%2(0$ %>%:%01< (' %;25 2%>>F ;0$ <( '()15E

sa = struct(‘Name’, {‘Kevin’, ‘Micah’}, ‘Age’, {19, 20})

%#D8I & %#DLI &Name:’Kevin’ Name:’Micah’ f@1(8U f@1(LO

/' (0% (' 15% %I%0K0":=%)%$ #0A"1< #< )%A>;2%$ D#15 ; $("=>%F ; <1)#0BF ; <1)"21")%F () ; 2%>>2(01;#0#0B (0>? (0% I;>"%F 674879 D#>> A>;2% 15;1 %>%:%01 #0 %I%)? <1)"21")% (' 15% )%<">1;01 ;));?E 45%0":=%) (' <1)"21")%< #0 15% ;));? #< <1#>> $%1%):#0%$ =? 15% >%0B15 (' 15% (15%) 2%>> ;));?< #0 15% '"021#(02;>>E

Page 51: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 51/101

sa = struct(‘Name’, {‘Kevin’, ‘Micah’, ‘Joash’, ‘Abel’}, ‘Age’, 19) %#D8I & %#DLI & %#DFI & %#DHI &Name:’Kevin’ Name:’Micah’ Name:’Joash’ Name:’ f516 ’ f@1(8U f@1(8U f@1(8U f@1(8U

sa = struct(‘Name’, {‘Kevin’}, ‘Age’, {19, 20}) %#D8I & %#DLI &Name:’Kevin’ f@1(8UName:’Kevin’ f@1(LO

45% <1)"21UV '"021#(0 #< >#G% 15% _()2%—?(" 2;0 A"1 ';#15 #0 ?(") =>;<1%)< ;0$ 1)? 1( <")I#I%D#15("1 #1F ="1 %I%01";>>? <(:% f%$# D#>> <5(D "A ;0$ 5;2G ?(" 1( A#%2%<E

A)*#F,): >5/7357/# 9//(61.

45% 2($% 1( A">> #0$#I#$";> %>%:%01< ("1 (' <1)"21")% ;));?< #< <#:A>? 15% )%I%)<% (' 15% $(1 UEV;<<#B0:%01 "<%$ 1( 2)%;1% 15%:E

%.A1;>3$@ & %#D'IB23160

45#< 2($% #< (0>? "<%'"> '() A">>#0B ("1 #0$#I#$";> %>%:%01< ')(: ; A;)1#2">;) <1)"21")%E_()1"0;1%>?F 15%)% ;)% 1D( (15%) D;?< 1( #0$%C <1)"21")% ;));?<E S(" 2;0 #0$%C ;0 %01#)% <1)"21")% =?>%;I#0B ("1 15% '#>%$0;:%E

%.A1;>3$@ & %#D'I

/0 15#< 2;<%F 15% ("1A"1 (' 15% #0$%C #< ;0(15%) <1)"21")% ;));?E Q=I#("<>?F ?(" 2(">$ ;><( #0$%C ;

);0B% (' <1)"21")% ;));?< "<#0B 15% 2(>(0 (A%);1()E i%)5;A< 15% :(<1 "<%'"> :%15($ '() #0$%C#0B<1)"21")% ;));?< #< 1( ;22%<< %I%)? %>%:%01 #0 ; A;)1#2">;) '#%>$L (02% ;B;#0F ?(" 2;0 "<% A;)%015%<%< '()'#%>$0;:%< <1()%$ ;< I;)#;=>%<E

%.A1;>3$@ & %#B23160%.A1;>3$@ & %#BD23160I

M0'()1"0;1%>?F #0$%C#0B ;0 %01#)% '#%>$ A)($"2%< :">1#A>% ("1A"1< 15;1 674879 $(%< 0(1;" tomatically store. It saves each value in the temporary variable “ans”, effectively overwriting all butthe final element. You will therefore need to enclose the variable you’re creating in square or curly=);2G%1< 1( 2)%;1% I%21()< ;0$ 2%>> ;));?< )%A)%<%01#0B ; '#%>$0;:%E

sa = struct(‘Name’, {‘Matthew’, ‘Mark’, ‘Luke’, ‘John’}, ‘Age’, {19, 20, 21,LLoICR#A1% & %#BR#A1 Names = ‘John’ nR#A1%o & %#BR#A1 Names = {‘Matthew’, ‘Mark’, ‘Luke’,‘John’} Pf@1%Q & %#Bf@1 f@1% & P8UM LOM L8M LLQ

And now we’ll take a look at the bunch ‘o’ functions associated with structure arrays.

Page 52: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 52/101

Page 53: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 53/101

A1J,#?*HI

/< ; 2%)1;#0 <1)#0B (0% (' 15% '#%>$0;:%< #0 ; <1)"21")%\ /<'#%>$UV )%1")0< ; >(B#2;> 1)"% () ';><%E

6.@3<#6 & 3%23160D%#M 23160I

A15/735HI

P()G< @"<1 >#G% #<25;)UVF #< 0":%)#2UVF ;0$ #<2%>>UVE *;0 ?(" B"%<< D5;1 #1 $(%<\

6.@3<#6 & 3%%;-/<;D%.A1;>3$@I

That’s pretty much it for structure arrays, believe it or not. Just memorize all the little rules and'"021#(0< =%2;"<% <1)"21")% A)(=>%:< >(I% 1( A(A "A (0 15% '#0;> %C;:E / @"<1 5;I% (0% 15%()%1#2;>

$#<2"<<#(0 1( ;$$ 15;1 :;? =% "<%'">E

P5%0%I%) ?(" 5;I% ; 2(>>%21#(0 (' $;1; <"25 ;< ; I%21()F ;));?F 2%>> ;));?F () <1)"21")% ;));? ;0$?(" D#<5 1( A">> ("1 (0 %>%:%01 ;1 ; 1#:% UA)(=;=>? 1( A%)'(): <(:% G#0$ (' >(B#2;> () 2(0$#1#(0;><1;1%:%01V ?(" 5;I% 1( "<% ; <%)#%< (' 0%<1%$ '() >((A<E 45% 0":=%) (' '() >((A< 0%2%<<;)? D#>> ;>D;?<=% %O";> 1( 15% 0":=%) (' $#:%0<#(0< #0 15% $;1; 2(>>%21#(0 U(0% '() I%21()<F 1D( '() ;));?F %12EVE 45%#:A()1;01 15#0B 1( )%:%:=%) ;=("1 <1)"21")% ;));?< #< 15;1 15% <%1 (' '#%>$0;:%< ;$$< ;0 %C1);$#:%0<#(0F <( ; (0%K$#:%0<#(0;> <1)"21")% ;));? ;21< >#G% ; 1D(K$#:%0<#(0;> (=@%21E

!#I%0 ; (0%K$#:%0<#(0;> <1)"21")% ;));? D#15 "0G0(D0 '#%>$0;:%<F 5(D D(">$ ?(" #0$%C %;25%>%:%01 #0$#I#$";>>?\

23160% & 23160$#A1%D%#IC2.- 3 & 8(61$@;>D%#I

2.- l & 8(61$@;>D<#I' & %#D3IBD23160%nloIC

1$01$0

+%2(0$F )%:%:=%) 15;1 ?(" 2;0 "<% <1)2:AUV 1( 2(:A;)% ; <1)#0B 1( ; 2%>> ;));? (' <1)#0B< 1( '#0$:;125%<E _#%>$0;:%<UV ("1A"1< ; 2%>> ;));? (' <1)#0B<E

Page 54: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 54/101

+%21#(0 ,Y3 a%2")<#(0

7 '"021#(0 2;0 ;21";>>? 2;>> #1<%>' #0 15% <;:% D;? #1 D(">$ 2;>> ;0(15%) '"021#(0E P5%0 ;'"021#(0 2(01;#0< ; 2;>> 1( #1<%>'F #1 #< 2;>>%$ ; )%2")<#I% '"021#(0 U15% ;21 (' ; '"021#(0 2;>>#0B #1<%>' #<2;>>%$ )%2")<#(0VE 7 )%2")<#I% 2;>> 2;"<%< 674879 1( (A%0 ;0(15%) 2(::;0$ D#0$(D 2;>>%$ ; <1;2G');:% (0 1(A (' 15% (0% ?(") '"021#(0 #< )"00#0BE R;25 <"22%<<#I% 2;>> (A%0< ?%1 ;0(15%) <1;2G ');:%F;0$ 15% A)(2%<< 2(01#0"%< "01#> 0( :()% )%2")<#I% 2;>>< ;)% :;$%E 674879 15%0 %I;>";1%< 15% %;25#0$#I#$";> <1;2G ');:% <1;)1#0B D#15 15% 6Q+4 aR*RJ4 QJRE

45#0G (' ; <1;2G (' A;A%)< (0 ; 1;=>%E /' ?(" <%1 ?(") 2;>2">"<F A5?<#2<F ;0$ 25%:#<1)? 5(:%D()Gon a desk and then pick them up one at a time, you’ll finish your chemistry homework first because it%0$< "A (0 1(AE 45#< D#>> ;>> <%%: );15%) %15%)%;> "01#> D% >((G ;1 ;0 %C;:A>%E

M0'()1"0;1%>?F 5;I#0B ?(") '"021#(0 2;>> #1<%>' #:A(<%< ; '%D I%)? <A%2#'#2 >#:#1;1#(0< 1( ;I(#$

infinite loops. Here are three “pillars” of recursion.

,E 45% '"021#(0 2;>>< #1<%>'EYE 45% '"021#(0 2(01;#0< ; 1%):#0;1#0B 2(0$#1#(0E-E +"22%<<#I% 2;>>< :(I% 15% '"021#(0 1(D;)$ 15% 1%):#0;1#0B 2(0$#1#(0E

And here is the basic “template” you’ll be using with recursion.

32 X;1-A3$#;3$@ <.$03;3.$WX<.01 56.<gW

16%132 XA#)51 #$.;>1- ;1-A3$#;3$@ <.$03;3.$M #0 3$23$3;/AWX<.01 56.<gW

16%1X-1</-%341 <#66W

+( D5;1 (0 %;)15 #< ; 1%):#0;1#0B 2(0$#1#(0\ 45% :(<1 <%I%)% >#:#1;1#(0 (' )%2")<#(0 #< 15;1F #'>%'1 "025%2G%$F 15% '"021#(0 D#>> 2;>> #1<%>' #0'#0#1%>?F (A%0#0B ;0 #0'#0#1% 0":=%) (' <1;2G ');:%< ;0$%I%01";>>? 2);<5#0B ?(") 2(:A"1%)E 674879 5;< ; ="#>1K#0 <;'%B";)$ ;B;#0<1 15#< A(<<#=#>#1?L #1 D#>> B#I%?(" ; D;)0#0B ;0$ ;<G '() ?(") A%):#<#(0 =%'()% (A%0#0B 1(( :;0? <1;2G ');:%< ;1 (02%E J%I%) B#I% #1A%):#<<#(0 1( $( <(E

4( A)%I%01 15#< 1);B%$?F ?(" <#:A>? 25;0B% 15% #0A"1< (' %;25 )%2")<#I% 2;>> U:;G% 15%:I;)#;=>%V #0 <"25 ; D;? 15;1 15%? ;AA)(;25 ; G0(D0 I;>"%E RI%01";>>?F 15% '"021#(0 D#>> )%;25 15#<“terminating condition” and immediately resolve all waiting stack frames. Let’s look at the famous'#=(0;22# %C;:A>% 1( <%% 5(D 15#< D()G<E

7 '#=(0;22# <%O"%02% #< ; <%)#%< (' 0":=%)< D5%)% %;25 %>%:%01 #< %O";> 1( 15% <": (' 15%A)%I#("< 1D( %>%:%01<E 45% '#)<1 1D( 0":=%)< ;)% ;)=#1);)#>? 25(<%0 ;< N%)( ;0$ (0%E jF,F,FYF-F`FcF,-FY,

Page 55: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 55/101

;0$ <( '()15E P% D;01 1( D)#1% ; )%2")<#I% '"021#(0 15;1 1;G%< #0 ; 0":=%) ;0$ )%1")0< 15% '#=(0;22#I;>"% ;1 15;1 A(<#1#(0E

2/$<;3.$ ./; & 235 D$/AI 32 $/A&&8

./; & OC 16%132 $/A&&L ./; & 8C

h[>1%1 #-1 ./- ;?. ;1-A3$#;3$@ <.$03;3.$%B j543./%6)M ;>1 %1_/1$<1 <#$$.;h<.$;#3$ #$) 161A1$;% 512.-1 =.%3;3.$ .$1B

16%1 ./; & 235D$/AN8I 7 235D$/ANLIC

h[>3% 63$1 <.$%;3;/;1% ;>1 -1</-%341 <#66B `f[]f\ 14#6/#;1% 1#<> -1</-%341h<#66 <.A=61;16) 512.-1 <.$;3$/3$@ 23$3%>3$@ ;>1 <.01B a.- >3@>1- $/A51-%Mh1#<> <#66 ?366 .=1$ A#$) %;#<g 2-#A1% ;>#; _/3<g6) 51<.A1 <.A=./$010 63g1h5-#$<>1% .2 # ;-11B ,#<> %/<<1%%341 <#66 -10/<1% ;>1 4#6/1 .2 ;>1 3$=/;h/$;36 3; 3% 1_/#6 ;. .$1 .- ;?. D;>1 ;1-A3$#;3$@ <.$03;3.$IB

1$0 1$0

/' ?(" ;11%:A1 1( "<% 15#< '"021#(0 1( %I;>";1% ; :($%);1%>? 5#B5 0":=%) >#G% `jF ?(" D#>> '#0$15;1 674879 1;G%< ;>> %1%)0#1? 1( )%1")0 15% ;0<D%)—#1 D(">$ ;>:(<1 =% ';<1%) 1( %I;>";1% 15%<%O"%02% =? 5;0$E P5?\ 45% %0():("< =);025%< (' )%2")<#I% 2;>>< ;21";>>? %0$ "A %I;>";1#0B 15% <;:%numbers over and over again. Since MATLAB doesn’t inherently sa I% 15% I;>"% '() '#=UYjVF #1 5;< 1()%%I;>";1% #1 %;25 1#:% #1 #< A)(:A1%$ 1( $( <(E

45"<F 15% (15%) :;@() >#:#1;1#(0 (' )%2")<#(0 #< 15;1 #1 =%2(:%< A(#01>%<<>? )%$"0$;01 '() ;>> ="115% <#:A>%<1 1;<G<E P5?F 15%0F D(">$ ?(" "<% )%2")<#(0 '() ; A)(=>%: <uch as this? You wouldn’t.

45% (0>? )%;<(0 ?(" >%;)0 )%2")<#(0 #0 15#< 2>;<< #< <( ?(" 2;0 =% 1%<1%$ (0 #1E Q0 );)% (22;<#(0<F)%2")<#(0 #< 15% (0>? D;? 1( %''#2#%01>? <(>I% ; A)(=>%:F ="1 '() <(:%15#0B >#G% 15#< ?(" D#>> ;>D;?< =%=%11%) (' "<#0B #1%);1#(0 #0<1%;$E

7< ; '#0;> 0(1% ;0$ D;)0#0BF 2(0<#$%) D5;1 D(">$ 5;AA%0 #' ;0?15#0B ="1 ; A(<#1#I% #01%B%) D%)%#0A"11%$ #01( 15% ;=(I% '"021#(0E /1 D(">$ )"0 '()%I%)E

45% '#=(0;22# '"021#(0 #0I(>I%$ ;AA)(;25#0B 15% 1%):#0;1#0B 2(0$#1#(0 =? )%$"2#0B 15% I;>"% ('the input. Let’s look at an example involving a different type of terminating condition.

P)#1% ; '"021#(0 )%2")<#I%+": 15;1 1;G%< #0 ; I%21() ;0$ )%1")0< 15% <": (' #1< %>%:%01< "<#0B )%2")<#(0E2/$<;3.$ ./; & -1</-%341S/AD41<I

32 61$@;>D41<I&&8 ./; & 41<C

16%1 ./; & 41<D8I 7 -1</-%341S/AD41<DL(1$0IIC

1$0 1$0

Page 56: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 56/101

Q02% ;B;#0F D% (0>? "<%$ )%2")<#(0 =%2;"<% 15% $#)%21#(0 1(>$ "< 1(E 70? <;0% A%)<(0 D(">$5;I% <#:A>? "<%$ 15% <":UV '"021#(0E 45#< 1#:%F D% ;AA)(;25%$ 15% 1%):#0;1#0B 2(0$#1#(0 =? )%$"2#0B15% >%0B15 (' (") #0A"1 ="1 >%;I#0B 15% I;>"%< "025;0B%$E

_#0;>>?F <(:% A)(=>%:< :;? ;<G ?(" 1( G%%A 1);2G (' 15% 0":=%) (' )%2")<#I% "<%$ 1( (=1;#0 15%

<(>"1#(0E

P)#1% ; '"021#(0 )%2")<#I%8%0B15 15;1 1;G%< #0 ; I%21() ;0$ )%1")0< #1< >%0B15 "<#0B )%2")<#(0E

2/$<;3.$ ./; & -1</-%341]1$@;>D41<I 32 61$@;>D41<I&&O

./; & OC 16%132 61$@;>D41<I&&8

./; & 8C 16%1

./; & 8 7 -1</-%341]1$@;>D41<D8(1$0N8IIC 1$0

1$0

45% ';21 15;1 "<#0B 15% >%0B15UV '"021#(0 D;< 0%2%<<;)? #< ; 1%<1;:%01 1( 15% "<%>%<<0%<< (')%2")<#(0E

i%)5;A< 15% (0>? 1;<G '() D5#25 )%2")<#(0 #< ;=<(>"1%>? 0%2%<<;)? #0I(>I%< 15% I;)#;=#>#1? (' 2%>><;0$ <1)"21")%<E 45% I;)#;=>% 2(">$ A(1%01#;>>? 2(01;#0 ;0? 0":=%) (' 2%>>< ;0$ <1)"21")%< 2(01;#0%$within other cells and structures. Thus, we would use recursion to “unwrap” the contents of thevariable. Let’s take cells as an example.

P)#1% ; '"021#(0 "0D);A*%>> 15;1 1;G%< #0 ; (0%K$#:%0<#(0;> 2%>> ;));? ;0$ >(2;1%< %I%)? 0(0K2%>>%>%:%01E 45% '"021#(0 <5(">$ A)#01 15% I;>"% (' ;>> 0(0K2%>> %>%:%01< 1( 15% 2(::;0$ D#0$(DF

<%A;);1%$ =? <A;2%<E 45% 2%>>< D#>> 0(1 2(01;#0 <1)"21")%< ="1 :;? 2(01;#0 (15%) 2%>><E

2/$<;3.$ /$?-#=c166D<#I 2.- 3 & 8(61$@;>D<#I

32 3%<166D<#D3II /$?-#=c166D<#D3II

16%132 e3%1A=;)D<#D3II 2=-3$;2D<#D3II

1$0 1$0

1$0

_#0;>>?F 15% 47< :;? '() <(:% )%;<(0 $%2#$% 1( ;<<#B0 ; $)#>> A)(=>%: 15;1 #< "0<(>I;=>% 15% D;?#1 #< D)#11%0E a%:%:=%) 15;1 15% QJ8S D;? 1( ;AA)(;25 ; 1%):#0;1#0B 2(0$#1#(0 $")#0B )%2")<#I% 2;>>< #<1( I;)? 15% #0A"1< (' 15% '"021#(0E /' ?(" 0%%$ 1( 25;0B% ; I;)#;=>% 15;1 #< 0(1 ;0 #0A"1 1( 15% '"021#(0 #0()$%) 1( ;AA)(;25 15% 1%):#0;1#0B 2(0$#1#(0F 15% A)(=>%: #< "0<(>I;=>%E +#:A>? D)#1% ; 5%>A%) '"021#(0'() ?(") '"021#(0 15;1 "<%< :()% #0A"1< 15;0 15% ()#B#0;>E

Page 57: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 57/101

+%21#(0 ,-3 i>(11#0B

Compared to the concepts we’ve been dealing with recently, plotting is both fun and easy.P5#>% 674879 5;< 15% 2;A;=#>#1? 1( A)($"2% ;>:(<1 ;0? 2(02%#I;=>% G#0$ (' B);A5 () 25;)1F *+ ,-.,<%%:< 1( =% 2(02%)0%$ (0>? D#15 =;<#2 1D(K$#:%0<#(0;> B);A5< ;0$ 15)%%K$#:%0<#(0;> <")';2%<E 45%2(")<% <25%$">% <(:%1#:%< A)%<%01< 15%<% ;< 1D( <%A;);1% <%21#(0<F ="1 '() 2>;)#1? D% D#>> G%%A #1 ;<(0% B"#$%E

9;<#2 A>(11#0B A)%<%01< 0( $#''#2">1 () 15%()%1#2;> 2(02%A1<E 7>> ?(" 5;I% 1( $( #< :%:()#N% ; 0%D<>%D (' '"021#(0< ;0$ 15%0 "<% 15% G0(D>%$B% ?(" ;>)%;$? 5;I% 1( $%1%):#0% 15% ;AA)(A)#;1% #0A"1< 1(A)($"2% 15% $%<#)%$ B);A5E

a%2;>> ')(: 15% $#<2"<<#(0 (0 '"021#(0< 15;1 <(:% '"021#(0< 2;0 =% )"0 D#15("1 <A%2#'?#0B ;0?("1A"1E i>(11#0B A)(=>%:< ')%O"%01>? :;G% "<% (' 15#< 0";02% =? )%O"#)#0B ?(" 1( A)($"2% ; A>(1 );15%)

15;0 )%1")0 ;0 ("1A"1E 45%)%'()%F ?(" 0%%$ 1( )%:%:=%) 15#< '"021#(0 5%;$%) 1%:A>;1%3

2/$<;3.$ $#A1K.2K2/$<;3.$ D3$=/;8M 3$=/;LM 3$=/;FI

O?&5HI

Strangely enough, MATLAB’s plotting function is actually called plot(). Plot() takes in a vector ofCK$;1;F ; I%21() (' ?K$;1;F ;0$ ;0 (A1#(0;> 25;);21%) <1)#0BL #1 A)($"2%< U0(1 ("1A"1<V ; 1D(K$#:%0<#(0;>C? A>(1 (' 15% #0A"1 $;1;E R;25 A(#01 #< ;"1(:;1#2;>>? 2(00%21%$ 1( 15% A)%I#("< (0% D#15 ; <1);#B51 >#0%E

MATLAB’s default plot utilizes a solid blue line. However, you can change this by adding a25;);21%) <1)#0B ;< ; 15#)$ #0A"1 1( 15% A>(1 '"021#(0E 45% '#)<1 25;);21%) <A%2#'#%< ; 2(>()F 15% 0%C125;);21%) <A%2#'#%< ; A>(1 <?:=(>F ;0$ 15% )%:;#0$%) (' 15% <1)#0B <A%2#'#%< ; >#0% 1?A% U<(>#$ >#0%F $;<5%>#0%F %12EVE H%)% #< ; 25;)1 (' )%>%I;01 <?:=(>< '() ?(" 1( A%)"<%3

= =>"% E A(#01 K <(>#$B B)%%0 ( 2#)2>% 3 $(11%$) )%$ C CK:;)G KE $;<5$(12 2?;0 T A>"< KK $;<5%$: :;B%01; ] <1;)? ?%>>(D < <O";)%G =>;2G $ $#;:(0$D D5#1%

=6.;D'M)Mr5ErI =6.;D'M)MrgNBrI =6.;D'M)Mr?0NNrI

Page 58: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 58/101

P5%0 2)%;1#0B 2>(<%$ <5;A%<F )%:%:=%) 1( )%A%;1 15% '#)<1 <%1 (' 2(()$#0;1%<L (15%)D#<%F 674879 D#>>0(1 G0(D 1( $);D ; '#0;> >#0% =;2G 1( #1E _() %C;:A>%F

=6.;DPN8M N8M 8M 8QM P8M N8M N8M 8QI

A>(1< (0>? 15)%% <#$%< (' 15% "0#1 <O";)%—15% 1(A #< 0(1 2(00%21%$E P% D(">$ 0%%$ 1( ;$$ ; '#'152(()$#0;1% #$%01#2;> 1( 15% '#)<1E

=6.;DPN8M N8M 8M 8M N8QM P8M N8M N8M 8M 8QI

O&?(/ %&&/*,)(5#1.

i>(11#0B D#15 A(>;) 2(()$#0;1%< #< ; 1%250#O"% "<%$ 1( $);D 2#)2>%K>#G% <5;A%<E e);D#0B ; 2#)2>% =A>(11#0B #0$#I#$";> CK? 2(()$#0;1%< D(">$ =% $#''#2">1 ;1 =%<1F <(we turn ‘x’ and ‘y’ into functions of ‘r’and ‘theta’ (radius and angle) using the following conversions:

' & -BE<.%D;>1;#I) & -BE%3$D;>1;#I

By simply adjusting the radius and angle from the origin, we can “sweep out” any circle K>#G% ;)%;(0 15% C? A>;0e. Here’s a picture from Wikipedia.

So, to plot an ordinary circle of radius three, we would set ‘r’ equal to three and allow ‘theta’ torange from 0 to 2π. Linspace() is particularly useful here for generating a bunch of points, namely 100.

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

-2 -1.5 -1 -0.5 0 0.5 1 1.5 2-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

Page 59: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 59/101

- & FC;>1;# & 63$%=#<1DOMLE=3IC=6.;D-BE<.%D;>1;#IM -BE%3$D;>1;#II

By setting ‘r’ equal to a range of values as well, we can make interesting two K$#:%0<#(0;> <A#);>shapes. Here we’ll let ‘theta’ repeat three times to ensure multiple revolutions.

- & 63$%=#<1DOM!MFOOIC;>1;# & 63$%=#<1DOM LE=3IC;>1;# & P;>1;# ;>1;# ;>1;#QC=6.;D-BE<.%D;>1;#IM -BE%3$D;>1;#II

P5%0 A>(11#0B 1D(K$#:%0<#(0;> <5;A%<F @"<1 =% ;D;)% (' 15% B%(:%1)? #0I(>I%$ ;0$ "<% A(>;)2(()$#0;1%< D5%0 0%2%<<;)?E

D,:7/# D7)35,&)1.

45%)% ;)% 0":%)("< '"021#(0< 674879 "<%< 1( ;$@"<1 ;C%< ;0$ >;=%> '#B")%<E f"<1 G0(D 15%:F;0$ A>%;<% )%:%:=%) 15;1 :;0? (' 15% #0A"1< 6M+4 9R +4a/J!+E

i>(1 >;=%>#0B

;3;61D%;-3$@I h=/;% # ;3;61 .$ ;>1 =6.; '6#516D%;-3$@I h6#516% ;>1 'N#'3% )6#516D%;-3$@I h6#516% ;>1 )N#'3% d6#516D%;-3$@I h)1%M ?1 ?366 51 /%3$@ ;>1 dN#'3% #% ?166 61@1$0D%;-3$@I %you probably won’t ever use this

7C#< ;$@"<1#0B

#'3% %_/#-1 hA#g1% ;>1 </--1$; #'3% 5.' %_/#-1 3$ %3d1 #'3% ;3@>; hA#g1% ;>1 %A#661%; =.%%3561 #'1% ;. 03%=6#) ;>1 =6.; #'3% 1_/#6 hA#g1% ;>1 #'1% .2 1_/#6 61$@;>B [>1-1 #-1 .;>1- #'3% .=;3.$%M 5/;they don’t matter. @-30 .$ h;/-$% .$ ;>1 @-30 .$ )./- </--1$; =6.;

-5 -4 -3 -2 -1 0 1 2 3 4 5-5

-4

-3

-2

-1

0

1

2

3

4

-3 -2 -1 0 1 2 3-3

-2

-1

0

1

2

3

Page 60: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 60/101

%CD.

In the same way that ‘clc’ clears the command window, ‘clf’ clears the current figure.

4&?* &)

S%<F 15#< #< ;21";>>? ; '"021#(0E M0'()1"0;1%>?F 674879 ;"1(:;1#2;>>? (I%)D)#1%< ?(") 2"))%01plot whenever you try to plot something else. To prevent this, you must toggle a command called ‘hold’.‘Hold on’ allows you to add more plots to the same figure, while ‘hold off’ resets MATLAB’s default=%5;I#()E 45#< #< R7+S 1( '()B%1 (0 1%<1<E

>7N2?&5HI

/' ?(" D;01 1( A>;2% :">1#A>% #0$#I#$";> A>(1< #0 15% <;:% '#B")%F ?(" 2;0 "<% <"=A>(1UV 1(()B;0#N% 15%: #01( ; B)#$E 45% #0A"1< ;)% 15% 0":=%) (' )(D< #0 15% )%<">1#0B '#B")%F 15% 0":=%) ('2(>":0< #0 15% )%<">1#0B '#B")%F ;0$ 15% #0$#I#$";> A>(1 ?(" D#<5 1( :($#'?E

M0>#G% D5%0 #0$%C#0B ;));?<F 674879 )%;$< #0$#I#$";> A>(1< ')(: >%'1 1( )#B51F >#G% ; =((GE 7< ;0example, we’ll make six plots in one 2x3 figur %E +"=A>(1UV :"<1 2;>>%$ (02% '() %I%)? 0%D A>(1E

' & O(!C%/5=6.;DLMFM8I=6.;D'M6.@D'II%/5=6.;DLMFMLI=6.;D'M'I%/5=6.;DLMFMFI=6.;D'M'BJLI%/5=6.;DLMFMHI=6.;D'M%3$D'II%/5=6.;DLMFM!I=6.;D'M 8BG'I%/5=6.;DLMFM*I=6.;D'M'BGHI

J(1#2% 15% ()$%) (' 15% <"=A>(1<3

1 2 34 5 6

%/5=6.;D-.?%M <.6/A$%M </--1$;K=6.;I

0 50

0.5

1

1.5

2

0 50

1

2

3

4

5

0 50

5

10

15

20

25

0 5-1

-0.5

0

0.5

1

0 50.2

0.4

0.6

0.8

1

0 50

0.5

1

1.5

Page 61: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 61/101

O?&5RHI

i>(1-UV D()G< %C;21>? 15% <;:% D;? ;< A>(1UVF %C2%A1 15;1 #1 1;G%< #0 15)%% I%21()< ;0$ A)($"2%< 15)%%Kdimensional plot. The only difference here is that we add a dimension ‘z’ that is a function of ‘x’and ‘y’. If you haven’t worked with this before, don’t worry—it’s actually pretty simple. Just note that

plot3() produces line plots, not surfaces (there are other functions for that). Let’s draw some pointless15)%%K$#:%0<#(0;> 2")I%3

' & O(8OC) & !(8!Cd & 'BJL 7 )C=6.;FD'M)MdI

@-30 .$xlabel(‘x Naxis’) ylabel(‘y Naxis’) zlabel(‘z Naxis’)

45)%%Kdimensional plotting will also work with polar coordinates. Just specify a ‘z’ value to

2())%<A(0$ 1( 15% (15%) 2(()$#0;1%<E S(" 2;0 A>(1 15)%%Kdimensional spirals by using ‘x’ and ‘y’ valuesfor a circle and letting ‘z’ range slowly upward. We’ll allow ‘theta’ to repeat again to obtain a cooler K>((G#0B <A#);>E

- & !C;>1;# & 63$%=#<1DOMLE=3IC;>1;# & P;>1;# ;>1;# ;>1;#QC' & -BE<.%D;>1;#IC) & -BE%3$D;>1;#ICd & 63$%=#<1DOM8OMFOOIC=6.;FD'M)MdI@-30 .$xlabel(‘x Naxis’) ylabel(‘y Naxis’) zlabel(‘z Naxis’)

0 2 4 6 8 105

10

150

20

40

60

80

100

120

x-axis

y-axis

z - a x

i s

-5

0

5

-5

0

50

2

4

6

8

10

x-axisy-axis

z

- a x

i s

Page 62: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 62/101

Page 63: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 63/101

B#1":/,*HI

J%C1 1( <"25 #0';:("< '"021#(0< ;< <1)1(GUV ;0$ 'A)#01'UVF :%<5B)#$UV #< (0% (' 15% :(<1 2(0'"<#0Bfunctions in CS 1371. The obvious question in the previous example is how to generate arrays like ‘xx’and ‘yy’ from ‘x’ and ‘y’ vectors. This is certainly possible but would require some complicated loops and

; >(1 (' "00%2%<<;)? D()GE 6%<5B)#$UV 1;G%< #0 1D( I%21()< ;0$ ("1A"1< 15(<% ;));?<E

45% I%21()< / "<%$ 1( 2)%;1% 15% ;));?< #0 15% A)%I#("< %C;:A>% D%)% C h ,3- ;0$ ? h `3cE P% 2;0#::%$#;1%>? <%% 15;1 15% )%<">1#0B ;));?< U=(15 (' 15% +76R <#N%V D%)% (' $#:%0<#(0 ZC-E 45% '(")2(:%< ')(: 15% >%0B15 (' 15% <%2(0$ #0A"1F D5#>% 15% 15)%% #< 15% >%0B15 (' 15% '#)<1—I%)? 1)#2G?E

6%<B)#$UV 5;< 1D( ("1A"1<E 45% '#)<1 ;));? 2(0<#<1< (' 15% '#)<1 I%21() )%A%;1%$ ;>(0B 15% )(D<(02% '() %;25 %>%:%01 #0 15% <%2(0$ I%21()E 45% <%2(0$ ;));? 2(0<#<1< (' 15% <%2(0$ I%21() )%A%;1%$along the columns once for each element in the first vector. This is just something you’ll have to:%:()#N%E

' & 8(FC) & !(TCP''M))Q & A1%>@-30D'M)I

CC h1 2 31 2 311 22 33

?? h 5 5 56 6 678 78 78

Obviously, we don’t need to use meshgrid() to create a ‘zz’ array since ‘z’ will always be afunction of ‘x’ and ‘y’.

>"(*,):.

P% 2;0 ;><( ;$@"<1 15% :;00%) #0 D5#25 674879 <5;$%< <");2% A>(1< 1( :;G% 15%: >((Gprettier. Shading, like ‘hold on’, does not require any parentheses.

%>#03$@ 26#; h%>#01% #66 =31<1% #% .$1 %.630 <.6.- 01;1-A3$10 5) ;>1 1$=.3$;4#6/1% %>#03$@ 3$;1-= h/%1% 63$1#- 3$;1-=.6#;3.$ ;. 1%;3A#;1 ;>1 4#6/1% .2 3$;1-3.-=.3$;%M =-.0/<3$@ # %A..;> %>#03$@ %>#03$@ 2#<1;10 h26#; %>#03$@ ?3;> 56#<g A1%> 63$1% ;. 034301 -1@3.$%B [>3%3% ;>1 012#/6; %>#03$@B

Page 64: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 64/101

P''M ))Q & A1%>@-30DO(!MH(TIC dd & ''BJL N ))BJLC %/5=6.;D8MFM8I %/-2D''M))MddI %>#03$@ 26#; ;3;61Dr%>#03$@ 26#;rI %/5=6.;D8MFMLI %/-2D''M))MddI %>#03$@ 3$;1-= ;3;61Dr%>#03$@ 3$;1-=rI%/5=6.;D8MFMFI %/-2D''M))MddI %>#03$@ 2#<1;10 ;3;61Dr%>#03$@ 2#<1;10rI

0

5

4

6

8

-80

-60

-40

-20

0

20

shading flat

0

5

4

6

8

-80

-60

-40

-20

0

20

shading interp

0

5

4

6

8

-80

-60

-40

-20

0

20

shading faceted

Page 65: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 65/101

%&?&/'(2.

_#0;>>?F D% 2;0 ;$@"<1 15% 2(>()< 674879 "<%< '() <5;$#0B <")';2%<E / D#>> >#<1 15% (A1#(0< =%>(DF="1 15%)% #< 0( A;)1#2">;) 0%%$ 1( )%:%:=%) 15%:E

<.6.-A#= >%4 <.6.-A#= >.; <.6.-A#= @-#) <.6.-A#= 5.$1 <.6.-A#= <.==1- <.6.-A#= =3$g <.6.-A#= ?>3;1 <.6.-A#= 26#@ <.6.-A#= 63$1% <.6.-A#= <.6.-</51 <.6.-A#= 4@# <.6.-A#= l1; <.6.-A#= =-3%A <.6.-A#= <..6 <.6.-A#= #/;/A$ <.6.-A#= %=-3$@ <.6.-A#= ?3$;1- <.6.-A#= %/AA1-

>&/5,): O&,)51.

One of CS 1371’s favorite test questions involves plotting points that aren’t necessary in;<2%0$#0B ()$%)E a%:%:=%) 15;1 674879 (0>? A>(1< A(#01< #0 15% ()$%) 15%? ;)% #0A"11%$EUnfortunately, calling the sort() function on the ‘x’ and ‘y’ values separately will mix up the points to beplotted because ‘y’ is a function of ‘x’ (not necessarily ascending). The secret is to use the second output

(' 15% <()1UV '"021#(0 1( <()1 %;25 I%21() #0 15% <;:% :;00%)E

P'M 3$01'Q & %.-;D'IC ) & )D3$01'IC

Page 66: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 66/101

+%21#(0 ,Z3 9($#%< (' a(1;1#(0

i%(A>% $%<A#<% =($#%< (' )(1;1#(0 =%2;"<%F "0>#G% )%B">;) A>(11#0BF #1 #< 0(1 #01"#1#I% "0>%<< ?(REALLY understand what you’re $(#0BE P% 2;0 )(1;1% 1D(K$#:%0<#(0;> A>(1< %#15%) ;)("0$ 15% ()#B#0 =?a fixed angle ‘theta’ or around an axis, creating an interesting K>((G#0B <")';2%E 45% >;11%) #< ;21";>>? 15%same “bodies of rotation” example as is used in calculus I to study integra 1#(0E

M&5(5,&) 9/&7)* 5"# ;/,:,).

4( )(1;1% ; 1D(K$#:%0<#(0;> A>(1 ;)("0$ 15% ()#B#0 =? ; '#C%$ ;0B>%F <#:A>? :;1)#C :">1#A>? 15%2(()$#0;1%< =? 15% 1D(K$#:%0<#(0;> )(1;1#(0 :;1)#C U15% )(1;1#(0 :;1)#C 6M+4 =% (0 15% >%'1VE 45%2(()$#0;1%< 15%:<%>I%< :"<1 =% ()B;0#N%$ #0 ; YC0 :;1)#CF D#15a row of ‘x’ data on top of a row of ‘y’$;1;E

− cos = J(1% 15;1 D% <5(">$ JQ4 "<% 15% $(1 UEV 1( :">1#A>? 15% :;1)#2%<F D5#25 D(">$ (0>? )%<">1 #0 ;0

%))() anyway. After the multiplication step, simply plot the ‘x’ and ‘y’ date by indexing the rows of theresulting matrix. I like to call the rotation matrix ‘R’. Note that ‘theta’ must be in radians.

;>1;# & =3C ' & NF(FC ) & 'BJLC %/5=6.;D8MLM8I =6.;D'M)I @-30 .$ ^ & P<.%D;>1;#I N%3$D;>1;#ICBBB %3$D;>1;#I <.%D;>1;#IQC A#; & ^ EP'C)QC %/5=6.;D8MLMLI $1?' & A#;D8M(IC $1?) & A#;DLM(IC =6.;D$1?'M $1?)I @-30 .$

45#< :%15($ (0>? D()G< '() ; 2("01%)2>(2GD#<% )(1;1#(0 B#I%0 #0 );$#;0<E 4( 2(0I%)1 ')(:$%B)%%< 1(radians, multiply by π/180. To rotate clockwise, multiply by K,E

-4 -2 0 2 40

1

2

3

4

5

6

7

8

9

-4 -2 0 2 4-9

-8

-7

-6

-5

-4

-3

-2

-1

0

Page 67: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 67/101

M&5(5,&) 9/&7)* () 9F,1.

45#< #< :"25 :()% 2(:A>#2;1%$ 15;0 )(1;1#(0 ;=("1 15% ()#B#0 =%2;"<% #1 1")0< ; 1D(K$#:%0<#(0;> A>(1 #01( ; 15)%%K$#:%0<#(0;> =($?F )%O"#)#0B "< 1( <A%2#'? ;0(15%) $#:%0<#(0E

H%)% / :"<1 #01)($"2% :()% =#N;))% *+ ,-., 0(1;1#(0E a(1;1#(0 %C;:A>%< ;)% "<";>>? $(0% D#15 NI<E C $;1;F D5#25 ;21";>>? :;G%< :()% <%0<% '() 2)%;1#0B 15)%%Kdimensional bodies. The ‘zx’ plane isB%0%);>>? $%A#21%$ ;< $#)%21>? #0 ')(01 (' ?(" ;0$ A%)A%0$#2">;) 1( ?(") >#0% (' <#B51 U?(") 2(:A"1%)screen), with the ‘y’ axis stretching ahead of you in space (behind your computer screen). Rotatingaround the ‘y’ axis would now be rotation about the origin, so we only need to worry about rotationaround the ‘x’ and ‘z’ axes.

From my experience, problems are usually given with ‘u vs. v’ data rather than ‘x vs. z’ data “to

avoid confusion.” They’re the same thing. To create a three K$#:%0<#(0;> )(1;1#(0 =($?F <#:A>? '(>>(D U():%:()#N%V 15#< >#<1 (' <1%A<E

,E Make ‘theta’ using linspace(). YE Use meshgrid() to convert ‘u’ and ‘theta’ to ‘uu’ and ‘ttheta’. -E Use meshgrid() to convert ‘v’ and ‘theta’ to ‘vv’ and ‘ttheta’. ZE Decide which variable (‘uu’ or ‘vv’) is always equal to the radius and set it to ‘rr’. `E +et the variable (‘xx’, ‘yy’, or ‘zz’) of the rotation axis equal to ‘uu’ or ‘vv’.

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 50

5

10

15

20

25

x-axis

z - a x

i s

Page 68: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 68/101

bE Set the other two variables equal to ‘rr.*cos(ttheta)’ and ‘rr.*sin(ttheta)’. .E M<% <")'UV () :%<5UV 1( A>(1 15% )%<">1#0B =($?E

45;1 >#<1 A)(=;=>? :;$% ;=<(>"1%>? 0( <%0<%F <o let’s work through an example. We want to plotthe rotation of the above ‘xz’ data around the x K;C#<E

/ & O(!C 4 & /BJLC h[>1%1 ?366 51 @341$ 3$ ;>1 =-.561A %;#;1A1$;B ;>1;# & 63$%=#<1DOMLE=3IC h[>3% 1$%/-1% # <.A=61;1 -.;#;3.$B P//M ;;>1;#Q & A1%>@-30D/M;>1;#IC hS;1= .$1B P44M ;;>1;#Q & A1%>@-30D4M;>1;#IC hS;1= ;?.B ;;>1;# 3% 1'#<;6) ;>1 %#A1M %. 0.$r; ?.--) #5./; .41-?-3;3$@ 3;B -- & 44C hV3%/#63d1 ;>1 23$#6 23@/-1B i2 ?1 ;#g1 # <3-</6#- %63<1 =#-#6616 ;. ;>1h)N#'3%M ;>1 -#03/% .2 ;>#; <3-<61 3% #6?#)% 1_/#6 ;. ;>1 4#6/1 .2 r4r #;h;>#; =.3$;B '' & //C h[>1 r'r 4#6/1 0.1%$r; <>#$@1M %3$<1 ?1r-1 -.;#;3$@ #-./$0 ;>1 'N#'3%B )) & --BE<.%D;;>1;#IC dd & --BE%3$D;;>1;#IC h[>1%1 #-1 #-53;-#-)B v/%; =3<g .$1B %/-2D''M))MddI %>#03$@ 3$;1-= '6#516Dr'N#'3%rI )6#516Dr)N#'3%rI d6#516DrdN#'3%rI

If we view the figure in the ‘xz’ plane, we see that the original graph has been mirrored along15% CK;C#<F %C;21>? ;< %CA%21%$E

431?DOMOI

01

23

45

-40

-20

0

20

40-30

-20

-10

0

10

20

30

x-axisy-axis

z - a x

i s

Page 69: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 69/101

Now we’ll rotate the same plot around the z K;C#<E

/ & O(!C 4 & /BJLC ;>1;# & 63$%=#<1DOMLE=3IC P//M ;;>1;#Q & A1%>@-30D/M;>1;#IC P44M ;;>1;#Q & A1%>@-30D4M;>1;#IC -- & //C h[>1 3A#@3$#-) <3-</6#- %63<1 $.? 631% 3$ ;>1 r')r =6#$1B [>1 h-#03/%D03%;#$<1 2-.A ;>1 dN#'3%I 3% 1_/#6 ;. r/rB dd & 44C hj$<1 #@#3$M ;>1 #'3% .2 -.;#;3.$ 51<.A1 23'10B [>3% ;3A1M ;>1 03%;#$<1 h#6.$@ ;>1 dN#'3%D/= #$0 0.?$I 3% 1_/#6 ;. ;>1 .-3@3$#6 r4rB '' & --BE<.%D;;>1;#IC )) & --BE%3$D;;>1;#IC hV1-) -1=1;3;341B %/-2D''M))MddI %>#03$@ 3$;1-= '6#516Dr'N#'3%rI )6#516Dr)N#'3%rI d6#516DrdN#'3%rI

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-25

-20

-15

-10

-5

0

5

10

15

20

25

x-axis

z - a x

i s

Page 70: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 70/101

431?DOMOI

-5

0

5

-5

0

50

5

10

15

20

25

x-axisy-axis

z - a x

i s

-5 -4 -3 -2 -1 0 1 2 3 4 50

5

10

15

20

25

x-axis

z - a x

i s

Page 71: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 71/101

Just for practice, we can rotate some ‘xy’ data.

/ &POM !M LM OQC4 & POM !M !M FOQC=6.;D/M4Ixlabel(‘x Naxis’) ylabel(‘y Naxis’)

9/&7)* F@(F,1.

/ &POM !M LM OQC 4 & POM !M !M FOQC ;>1;# & 63$%=#<1DOMLE=3IC P//M ;;>1;#Q & A1%>@-30D/M;>1;#IC P44M ;;>1;#Q & A1%>@-30D4M;>1;#IC -- & 44C '' & //C dd & --BE<.%D;;>1;#IC )) & --BE%3$D;;>1;#IC A1%>D''M))MddI %>#03$@ 3$;1-= '6#516Dr'N#'3%rI )6#516Dr)N#'3%rI d6#516DrdN#'3%rI

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 50

5

10

15

20

25

30

x-axis

y - a x i s

01

23

45

-40

-20

0

20

40-30

-20

-10

0

10

20

30

x-axisy-axis

z - a x

i s

Page 72: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 72/101

9/&7)* 6@(F,1

/ &POM !M LM OQC 4 & POM !M !M FOQC ;>1;# & 63$%=#<1DOMLE=3IC P//M ;;>1;#Q & A1%>@-30D/M;>1;#IC

P44M ;;>1;#Q & A1%>@-30D4M;>1;#IC -- & //C )) & 44C'' & --BE<.%D;;>1;#IC dd & --BE%3$D;;>1;#IC A1%>D''M))MddI %>#03$@ 3$;1-= '6#516Dr'N#'3%rI )6#516Dr)N#'3%rI d6#516DrdN#'3%rI

*(0<#$%) 15%<% %C;:A>%< 2;)%'">>?E a(1;1#(0 D#>> <%%: #02)%$#=>? 2(:A>#2;1%$ "01#> ?(""0$%)<1;0$ 15% 15("B51 A)(2%<<E

!"/##@8,'#)1,&)(? M&5(5,&) B(5/,3#1.

Finally, you can rotate a plot by a fixed angle ‘theta’ around the ‘x’, ‘y’, or ‘z’ axes by multiplying15% ;AA)(A)#;1% 15)%%K$#:%0<#(0;> )(1;1#(0 :;1)#CE 45#< :%15($ D()G< @"<1 >#G% 1D(K$#:%0<#(0;>)(1;1#(0 ;=("1 15% ()#B#0E 45%)% #< A)(=;=>? 0( 0%%$ 1( )%:%:=%) 15%<% <#02% 15%? );)%>? ;AA%;) (05(:%D()G () 1%<1 A)(=>%:<E

-4-2

02

4

0102030

-5

0

5

x-axisy-axis

z - a x

i s

Page 73: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 73/101

+%21#(0 ,`3 /:;B%<

674879 #< 2;A;=>% (' )%;$#0B #0 ;0$ :;0#A">;1#0B #:;B%< :"25 >#G% J(1%A;$ () RC2%> '#>%< ')(:file IO, although I can’t understand why anyone would want to use MATLAB to play with images._()1"0;1%>?F 15%)% ;)% (0>? ; '%D #:A()1;01 '"021#(0< ;0$ 2(02%A1< 1( >%;)0F <( 15#< #< (0% (' 15% %;<#%<11(A#2< #0 15% 2(")<%E

/:;B% ;));?< ;)% HM!RE J%I%) '()B%1 1( <"AA)%<< ?(") ("1A"1<E

=(30:/&7)* &) A'(:#1.

*(:A"1%)< <1()% ;0$ #01%)A)%1 #:;B%< ;< %0():("< ;));?< (' %>%:%01< 2;>>%$ A#C%><E R;25 A#C%>5;< 15)%% I;>"%< ;<<(2#;1%$ D#15 #13 )%$F B)%%0F ;0$ =>"%E 45% 2(:A"1%) #01%)A)%1< $#''%)%01

2(:=#0;1#(0< (' 15%<% 15)%% 0":=%)< ;< $#''%)%01 2(>()<L %;25 #0$#I#$";> A#C%> =%2(:%< (0% <(>#$ 2(>()F;0$ >;)B% 2(>>%21#(0< (' 15%<% 2(>()< =%2(:% #:;B%<E

45% A#C%> I;>"%< ;)% =;<%$ (0 :#C#0B 15% 15)%% A)#:;)? 2(>()< (' >#B513 )%$F B)%%0F ;0$ =>"%E 7>>2(>()< 2;0 =% :;$% ')(: $#''%)%01 2(:=#0;1#(0< (' 15(<% 15)%% 2(>()< (' >#B51E 7 A#C%> D#15 ;>> N%)(<D(">$$ )%A)%<%01 15% ;=<%02% (' >#B51F 15% 2(>() =>;2GF D5#>% ; A#C%> D#15 15% 5#B5%<1 A(<<#=>% I;>"%;>> 15)%% D(">$ =% A")% D5#1%E

674879 <1()%< #:;B%< #0 6CJC- 15)%%K$#:%0<#(0;> ;));?<F D#15 15% 15#)$ $#:%0<#(0)%A)%<%01#0B 15% 15)%% A)#:;)? 2(>()<E 45% #:;B% #1<%>' #< ;0 ;));? (' )%$ I;>"%< (0 1(A (' ;0 ;));? ('B)%%0 I;>"%< (0 1(A (' ;0 ;));? (' =>"% I;>"%<E

Page 74: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 74/101

<,)5SHI.

9%2;"<% 15% ;$$#1#(0 (' >#B51 :"<1 =% =("0$%$ =? ; '#0#1% >#:#1 U15% 2(>() D5#1%VF #:;B%< ;)%<1()%$ #0 ; <A%2#;> 0%D $;1; 1?A% 2;>>%$ "#01cF D5#25 <1;0$< '() "0<#B0%$ cK=#1 #01%B%)E 7 15()("B5$#<2"<<#(0 (' 15#< $%'#0#1#(0 D(">$ =% A(#01>%<< 5%)%F <( / D#>> 2(I%) 15% #:A()1;01 A(#01<E M#01c 0":=%)<

'"021#(0 >#G% )%B">;) $("=>%< %C2%A1 '() 15)%% $#''%)%02%<E

,E 7>> 0":=%)< >(D%) 15;0 15% :#0#:": I;>"% (' j ;)% ;"1(:;1#2;>>? <%1 1( jEYE 7>> 0":=%)< ;=(I% 15% :;C#:": I;>"% (' Y`` ;)% ;"1(:;1#2;>>? <%1 1( Y``E-E 7>> $%2#:;>< ;)% ;"1(:;1#2;>>? )("0$%$ "A () $(D0 1( 15% 0%;)%<1 D5(>% 0":=%)E

9;<#2;>>?F "#01c #< ; $;1; 1?A% 15;1 (0>? ;>>(D< '() D5(>% 0":=%)< );0B#0B ')(: j 1( Y``E 45#<:;G%< <%0<% #0 1%):< (' #:;B%< =%2;"<% ');21#(0;> A#C%> I;>"%< D(">$ =% :%;0#0B>%<<F ;0$ =>;2G UjV ;0$D5#1% UY``V :"<1 5;I% '#0#1% I;>"%<E

Luckily, the function that converts other data types to uint8 is very easy to remember. It’s called

"#01cUVE

#-- & /3$;TD#--I

/0 :(<1 #:;B% A)(=>%:<F D% D#>> '#)<1 2(0I%)1 15% #:;B% ;));? 1( $("=>%< =%2;"<% 15%? 2;0 =%:()% %;<#>? :;0#A">;1%$E M<";>>?F 15% '#0;> <1%A D#>> =% 1( 2(0I%)1 ;>> 15% $;1; =;2G 1( 1?A% "#01cE

/3$;TDFOOI #$% & L!!C/3$;TDN!I #$% & OC/3$;TDFB!I #$% & HC<6#%%D/3$;TD!II ans = ‘uint8’

A'/#(*HI.

674879 5;< ; ="#>1K#0 '"021#(0 1( )%;$ #:;B%< 2;>>%$ #:)%;$UVE /:)%;$UV 1;G%< #0 ; <1)#0B)%A)%<%01#0B ;0 #:;B% '#>% #0 15% 2"))%01 $#)%21()? ;0$ ("1A"1< ;0 #:;B% ;));? (' 1?A% "#01cE /:;B%;));?< ;)% @"<1 >#G% )%B">;) ;));?< D#15 ; 15#)$ $#:%0<#(0E 45% 0":=%) (' )(D< ;0$ 2(>":0< D#>> I;)?=%1D%%0 #:;B%<F ="1 15%)% D#>> ;>D;?< =% 15)%% >;?%)<3 )%$F B)%%0F ;0$ =>"%F #0 15;1 ()$%)E 6? <5()15;0for an image array is ‘im’.

3A & 3A-1#0D2361$#A1I

/0 15% <;:% D;? 15;1 1D(K$#:%0<#(0;> ;));?< ;)% #0$%C%$ =? )(D< '(>>(D%$ =? 2(>":0<F 15)%%K$#:%0<#(0;> ;));?< ;)% #0$%C%$ =? )(D<F 15%0 2(>":0<F 15%0 >;?%)<E S(" 2;0 2)%;1% 15)%%K$#:%0<#(0;>;));?< %#15%) =? :;0";>>? 2)%;1#0B %;25 >;?%) () =? "<#0B 15% 2;1UV '"021#(0F %CA>;#0%$ =%>(DE

f & A#@3<DFIC3AD(M(M8I & fC3AD(M(MLI & fC3AD(M(MFI & fC

Page 75: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 75/101

7>1%)0;1#I%>?F #1 #< %;<? 1( $#I#$% #:;B%< #01( >;?%)< "<#0B 15% <;:% :%15($E

3A & 3A-1#0D2361$#A1I-10 & 3AD(M(M8IC@-11$ & 3AD(M(MLIC56/1 & 3AD(M(MFIC

%(5HI.

45%)% #< ;><( ; :;B#2;> 674879 '"021#(0 15;1 2(02;1%0;1%< %O"#I;>%01>? <#N%$ ;));?< ;>(0B 15%15#)$ $#:%0<#(0F :"25 >#G% "<#0B <O";)% =);2G%1<E 45% #0A"1< <5(">$ =% 15% 0":=%) - U'() 15)%%K$#:%0<#(0;> 2(02;1%0;1#(0V '(>>(D%$ =? ;>> 15% ;));?< ?(" D#<5 1( 2(02;1%0;1%E

f & A#@3<DFIC3A & <#;DFMfMfMfIC

A'-/,5#HI.

/:D)#1%UV 1;G%< #0 ; 15)%%K$#:%0<#(0;> "#01c ;));? ;0$ <;I%< 15% 2())%<A(0$#0B #:;B% 1( 15%2"))%01 $#)%21()?E S(" :"<1 ;><( <A%2#'? 15% '():;1 #0 D5#25 ?(" D#<5 1( <;I% 15% #:;B% U@ABF =:AF %12EV;< ; <1)#0BE

3A?-3;1D#--M2361$#A1M2.-A#;I3A?- ite(A,’hello.jpg’,’jpg’) imwrite(A,’greetings.bmp’,’bmp’)

/' 15% #0A"1 ;));? 5;< (0>? (0% >;?%) #0<1%;$ (' 15)%%F #:D)#1%UV D#>> 2)%;1% ; B);?<2;>%$ #:;B%D#15 15% <;:% ;));? ;< ;>> 15)%% >;?%)<E

A'(:#HI ()* A'1"&-HI.

/:;B%UV ;0$ #:<5(DUV 2;0 =% "<%$ 1( $#<A>;? #:;B% ;));?< #0 15% 2"))%01 '#B")% D#0$(DE 45%:;#0 $#''%)%02% #< 15;1 #:;B%UV 2;"<%< 674879 1( $( <1);0B% 15#0B< 1( 15% #:;B% =%'()% $#<A>;?#0BF <"25;< ;$$#0B ;C#< :;)G< 1( #0$#2;1% A#C%> 0":=%)<F D5#>% #:<5(DUV @"<1 $#<A>;?< 15% #:;B%E /' 15% #:;B% #<1(( =#B 1( '#1 (0 15% <2)%%0F #:<5(DUV D#>> ;"1(:;1#2;>>? <2;>% #1 $(D0 1( ; :()% :;0;B%;=>% <#N%E P5%0

#0 $("=1F "<% #:<5(DUVE

3A#@1D3AI3A%>.?D3AI

Page 76: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 76/101

>(?#'.

/:;B% A)(=>%:< #0I(>I% :;0#A">;1#0B #:;B% ;));?< "<#0B I;)#("< ;>B()#15:< 1( A)($"2% 15%$%<#)%$ )%<">1<E J(0% (' 15%<% 2(02%A1< <5(">$ =% ;0? $#''%)%01 ')(: D5;1 D% 2(">$ ;>)%;$? A%)'():D#15 ;));?< (' $("=>%<E _() ;>> (' 15% '(>>(D#0B %C;:A>%<F / D#>> =% "<#0B ;0 #:;B% (' :? 2;1 1(

$%:(0<1);1% 15% )%<">1<E H#< 0;:% #< +;>%:F @"<1 >#G% 15% 1;>G#0B 2;1 ')(:2$0%+-$3 ,4# 5##-$6# 7+,!4 E

im = imread(‘salem.jpg’);

>,T#HI.

P% )%1")0 0(D 1( ; =)#%' )%2;A#1">;1#(0 (' 15% <#N%UV '"021#(0 "<%$ 1( '#0$ 15% 0":=%) (' )(D<

;0$ 2(>":0< #0 ;));?<E P5%0 "<%$ )%B">;)>? (0 ; 15)%%K$#:%0<#(0;> ;));?F <#N%NUV D#>> );15%) <1"A#$>?$%2#$% 1( :;G% "A '() 15% %C1); $#:%0<#(0 =? 1)#A>#0B 15% 0":=%) (' 2(>":0<F D5#25 D#>> A)(=;=>? 15)(Dyou off if you’re not watching for it. ALW 7S+ 2;>> <#N%UV D#15 15)%% ("1A"1< D5%0 $%;>#0B D#15 #:;B%<F%I%0 15("B5 ?(" ;>)%;$? G0(D 15%)% ;)% 15)%% >;?%)<E

P-.?M <.6M 6#)1-Q & %3d1D3AIC

If it makes you feel better, just replace ‘layer’ with a tilde so it won’t be saved in your workspace;< ; I;)#;=>%E

P-.?M <.6M eQ & %3d1D3AIC

Page 77: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 77/101

M#1,T,): A'(:#1.

/1 #< ('1%0 $%<#);=>% 1( :;G% ;0 #:;B% >;)B%) () <:;>>%) D#15("1 <#B0#'#2;01>? 25;0B#0B #1<;BB)%B;1% ;AA%;);02%E M0'()1"0;1%>?F ;$$#0B () $%>%1#0B );0$(: %>%:%01< ')(: 15% #:;B% ;));? D(">$%#15%) ;$$ () $%>%1% #0'():;1#(0 ')(: 15% #:;B% #1<%>'E

45% <(>"1#(0 #< 1( "<% #0$%C#0B 1)#2G< 1( %#15%) )%A%;1 () $%>%1% %I%0>? <A;2%$ )(D< ;0$ 2(>":0<4( :;G% ;0 #:;B% 1D#2% ;< >;)B%F D% 2(A? %I%)? )(D ;0$ 2(>":0 ;0 %C1); 1#:%L 1( 5;>I% 15% <#N%F D%$%>%1% %I%)? (15%) )(D ;0$ 2(>":0E 45% %;<#%<1 D;? 1( ;22(:A>#<5 15#< #< =? "<#0B 15% >#0<A;2%UV'"021#(0 1( 2)%;1% ; );0B% (' 15% $%<#)%$ 0":=%) (' #0$#2%< ;0$ 15%0 )("0$#0B 15% #0$#2%< 1( 15% 0%;)%<1D5(>% 0":=%)E /' D% #0$%C 15% ()#B#0;> #:;B% ;));? ;1 15#< 0%D ;));? (' A(<#1#(0 I;>"%<F 674879 D#>>;"1(:;1#2;>>? )%A%;1 () $%>%1% #0'():;1#(0 —15% "<% (' >#0<A;2%UV %0<")%< 15;1 15#< #0'():;1#(0 #< %I%0>?<A;2%$ ;0$ 15"< $#''#2">1 1( 0(1#2%E

Here we simply set ‘x’ and ‘y’ equal to the desired effect on rows and columns, )%<A%21#I%>?E 4(5;>I% 15% )(D< ;0$ $("=>% 15% 2(>":0<F "<% ChjE` ;0$ ?hYE

P-.?M <.6M 6#)1-Q & %3d1D3AIC-.?K3$01' & -./$0D63$%=#<1D8M -.?M -.?BE'IIC<.6K3$01' & -./$0D63$%=#<1D8M <.6M <.6BE)IIC3A & 3AD-.?K3$01'M <.6K3$01'M (IC3A%>.?D3AI

Q02% ;B;#0F )%:%:=%) 1( #0$%C )(D<F 2(>":0<F 7JeF ;>> 15)%% >;?%)< () #:<5(DUV D#>> A)($"2% ;B);?<2;>% #:;B% =;<%$ (0>? (0 ; <#0B>% >;?%)E

Q/(613(?,): A'(:#1.

/' ; 2%)1;#0 A#C%> 5;< 15% <;:% #01%0<#1? I;>"% '() )%$F B)%%0F ;0$ =>"%F 674879 #01%)A)%1< 15%2(>() ;< B);?L <:;>>%) 0":=%)< B%0%);1% $;)G%) <5;$%< (' B);?F ;< D% D(">$ %CA%21E 4( 2(0I%)1 ;2(>()'"> #:;B% 1( B);?<2;>% U<5;$%< (' B);? I;)?#0B ;22()$#0B 1( 15% #01%0<#1? (' 15% #0$#I#$";> A#C%><VF @"<1 1;G% 15% ;I%);B% I;>"% (' 15% 15)%% >;?%)< (' 15% #:;B% ;));?E 45;1 ;I%);B% I;>"% #< 15%0 )%A%;1%$15)%% 1#:%< 1( 2)%;1% #$%01#2;> )%$F B)%%0F ;0$ =>"% >;?%)<E

a%:%:=%) 15;1 1;G#0B ;I%);B%< $(%< 0(1 D()G I%)? D%>> D#15 $;1; 1?A% "#01cUV =%2;"<% #1;"1(:;1#2;>>? )("0$< ');21#(0< ;0$ 2;A< 0":=%)< ;1 Y``E +(:% 2(")<% ;$:#0#<1);1()< D#>> 1%>> ?(" 15;1?(" 2;0 ;I(#$ 15#< #<<"% =? $#I#$#0B 15)("B5 =? - '#)<1 D5%0 1;G#0B ;I%);B%<F ="1 15#< :%15($ 2(">$ ;><(

Page 78: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 78/101

A(1%01#;>>? ';#> #' 674879 $%2#$%< 1( )("0$ ; 0":=%) #0 ;0 "0%CA%21%$ $#)%21#(0E 4;G% :? ;$I#2% ;0$2(0I%)1 1( $("=>% ;0$ =;2G 1( "#01c —#1 D#>> A)(=;=>? <;I% ?(" <(:% 5%;$;25% #0 15% >(0B )"0E

3A & 0./561D3AIC@-#) & D3AD(M(M8I 7 3AD(M(MLI 7 3AD(M(MFIIGFC3A & <#;DFM @-#)M @-#)M @-#)IC3A & /3$;TD3AIC3A%>.?D3AI

!(0,): 5"# P#:(5,K# &J A'(:#1.

4;G#0B 15% 0%B;1#I% #< ; ';02? A5);<% '() )%I%)<#0B 15% #01%0<#1? (' %I%)? A#C%>—D5#1% =%2(:%<=>;2GF ;0$ =>;2G =%2(:%< D5#1%E f"<1 <"=1);21 15% %01#)% #:;B% ;));? ')(: Y``E

$1@#;341 & L!! – 3AC

>-(22,): C(6#/1.

*)%;1#I% #0$%C#0B ;><( B#I%< "< 15% ;=#>#1? 1( 25;0B% 15% ()$%) (' 15% 2(>() >;?%)< #0 ; 15)%%K$#:%0<#(0;> ;));?E a%:%:=%) D;;;? =;2G ')(: I%21()< 15;1 ;0 );0B% (' #0$#2%< #< <#:A>? ; I%21() ( '

A(<#1#(0 0":=%)<E 45"<F #0<1%;$ (' "<#0B ; 2(>(0 U3V 1( ;22%<< ;>> >;?%)< (' ;0 #:;B%F D% 2;0 "<% ; I%21()1( <D;A 15%m instead. Red=1, Green=2, and Blue=3. Let’s swap red and green.

3A & 3AD(M (M PL 8 FQIC3A%>.?D3AI

7< ?(" 2;0 <%%F 15% 1;=>% 0(D >((G< A")A>%E

Page 79: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 79/101

8,K,*,): A'(:#1.

e#I#$#0B #:;B%< #01( 5;>I%< () O";$);01< #< %;<? ="1 1%$#("<E 45#< @"<1 )%O"#)%< #0$%C#0B ;0$5%;I? "<% (' 15% )("0$UVF '>(()UVF () 2%#>UV '"021#(0< 1( ;I(#$ $%2#:;><E / ;>D;?< "<% )("0$UVE

3AD8(-./$0D1$0GLIM(M(IC [.= >#623AD-./$0D1$0GLI78(1$0M(M(IC \.;;.A >#623AD(M8(-./$0D1$0GLIM(IC ]12; >#623AD(M-./$0D1$0GLI78(1$0M(IC ^3@>; >#623AD8(-./$0D1$0GLIM8(-./$0D1$0GLIM(IC [.= -3@>; <.-$1-3AD8(-./$0D1$0GLIM-./$0D1$0GLI78(1$0M(IC [.= -3@>; <.-$1-3AD-./$0D1$0GLI78(1$0M8(-./$0D1$0GLIM(IC \.;;.A 612; <.-$1-3AD-./$0D1$0GLI78(1$0M-./$0D1$0GLI78(1$0M(IC \.;;.A -3@>; <.-$1-

!/()12&1,): A'(:#1 ()* O#/'75#HI.

For some unknown reason, the designers of MATLAB decided that using the apostrophe (‘) to1);0<A(<% 15)%%K$#:%0<#(0;> ;));?< <5(">$ 2;"<% ;0 %))()E S(" 2;0 %#15%) $#I#$% 15% #:;B% #01( 15)%%>;?%)< ;0$ 1);0<A(<% 15%: #0$#I#$";>>? () "<% 15% A%):"1%UV '"021#(0E

i%):"1%UV 1;G%< #0 ;0 ;));? ;0$ ; I%21() #0$#2;1#0B 15% ()$%) ?(" D#<5 1( )%;));0B% 15%$#:%0<#(0<E 45% 0;1");> ()$%) '() ; 15)%%K$#:%0<#(0;> ;));? #< k, Y -lF () )(D<F 2(>":0<F >;?%)<E 4( <D;A)(D< ;0$ 2(>":0<F "<% kY , -l #0<1%;$E

Q02% ;B;#0F )%:%:=%) 15;1 1);0<A(<#0B #< '"0$;:%01;>>? $#''%)%01 ')(: )(1;1#0BE J(1#2% 15;1 15%lizard is now in front of Salem’s RIGHT paw.

-10 & 3AD(M(M8IC @-11$ & 3AD(M(MLIC 56/1 & 3AD(M(MFIC ;-#$%K3A & <#;DFM-10rM@-11$rM56/1rIC3A%>.?D;-#$%K3AI

j^

;-#$%K3A & =1-A/;1D3AMPL 8 FQIC

Page 80: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 80/101

M&5(5,): A'(:#1.

P% 2;0 ;><( "<% 15% <;:% #0$%C#0B 1)#2G< ')(: 15% <%21#(0 (0 ;));?< 1( )(1;1% #:;B%< dj $%B)%%<2>(2GD#<% () 2("01%)2>(2GD#<%E

a%:%:=%) 15;1F #0 15% '#)<1 1D( 2;<%<F D% 1);0A(<% 15% ;));? ;0$ 15%0 )%I%)<% %#15%) 15% )(D<() 2(>":0<E 4( )(1;1% ,cj $%B)%%<F 1);0<A(<#1#(0 #< "00%2%<<;)?E

3A & =1-A/;1D3AMPL 8 FQIC ^.;#;1% <./$;1-<6.<g?3%1 3AD1$0(N8(8M(M(I

3A & =1-A/;1D3AMPL 8 FQIC ^.;#;1% <6.<g?3%13AD(M1$0(N8(8M(I

3AD1$0(N8(8M1$0(N8(8M(I ^.;#;1% 8TO 01@-11%

4( 2(0I%)1 >;)B%) () <:;>>%) ;0B>%< 1( 15%#) dj $%B)%% %O"#I;>%01<F %#15%) ;$$ () <"=1);21 -bj#0<#$% ; D5#>% >((A () 1;G% 15% ;=<(>"1% I;>"% (' 15% :($">"< ')(: -bjE 45% >;11%) :%15($ )%1")0< jF djF

,cjF () Y.jE 45;0G< B( 1( *;):#% *"$; '() 15#< #$%;E

#$@61 & #5%DA.0D#$@61MF*OIIC

_() ;>> (15%) 2(02%A1< <"25 ;< 2(02;1%0;1#(0F <#:">1;0%("<>? 25;0B#0B A#C%> I;>"%< U:;<G#0BVF;0$ =;<#2 :;0#A">;1#(0 #$%;<F )%'%) 1( 15% <%21#(0 (0 ;));?<E a%:%:=%) 15% B(>$%0 )">% (' #:;B%<3 15%?D()G @"<1 >#G% )%B">;) ;));?<E

Page 81: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 81/101

+%21#(0 ,b3 J":%)#2;> 6%15($<

J":%)#2;> :%15($< #< ; ';02? 1%): '() I;)#("< A)(=>%:< 15;1 D(">$ 0():;>>? =% 2":=%)<(:%but that MATLAB can solve easily using “brute force” methods. Although the actually scope of numerical:%15($< %02(:A;<<%< I%)? ';<2#0;1#0B 1(A#2< <"25 ;< )((1 '#0$#0BF >#0%;) )%B)%<<#(0F ;0$ <(>"1#(0< 1(A;)1#;> $#''%)%01#;> %O";1#(0<F 0(0% (' 15%<% ;)% 2(I%)%$ #0 *+ ,-.,E

/0<1%;$F 15#< <%21#(0 '(2"<%< (0 ; '%D =;<#2 1(A#2< >#G% <(>I#0B >#0%;) <?<1%:<F 2")I% '#11#0BF0":%)#2;> #01%B);1#(0F ;0$ >#0%;) #01%)A(>;1#(0E 6(<1 A)(=>%:< 2;0 =% <(>I%$ %;<#>? "<#0B 15%;AA)(A)#;1% ="#>1K#0 674879 '"021#(0E

>&?K,): C,)#(/ >615#'1.

7 <?<1%: (' :;0? >#0%;) %O";1#(0< U0( %CA(0%01< B)%;1%) 15;0 (0%V 2;0 =% <(>I%$ "<#0B =;<#2:;1)#C $#I#<#(0E H%)% / D#>> 0(1 ;11%:A1 1( %CA>;#0 15% '#0%) A(#01< (' >#0%;) ;>B%=);L 15% (0>? #:A()1;01%O";1#(0 #< 7F = b, where ‘A’ is a matrix of the coefficients for the linear equations, ‘ F’ is a column vector(' CKI;>"%< U15% <(>"1#(0< 1( 15% >#0%;)equations), and ‘b’ is a column vector of the right K5;0$ <#$%< (' ;>>15% %O";1#(0<E 45"<F 15% <?<1%:

g , T YCY h -ZC, – .ChY h K-

2;0 =% 1);0<'():%$ #01( 15% %O"#I;>%01 >#0%;) ;>B%=); %O";1#(0

1 24 −7 = 3−3

7> 15("B5 15#< A;)1#2">;) <?<1%: D(">$ =% %;<? 1( <(>I% =% 5;0$F 674879 2;0 <(>I% :"25 :()% 2(:A>%C<?<1%:< "<#0B #1< ;:;N#0B 2;A;=#>#1? 1( #0I%)1 :;1)#2%<E 45%)% ;)% 15)%% D;?< 1( <(>I% ;0? <?<1%: (' 15%'(): 7 F h =E

,E Multiply the inverse of ‘A’ times ‘b’ using the inv() function. Remember tha 1 ?(" :"<1 78P7S+:">1#A>? (0 15% >%'1K5;0$ <#$%E

YE Multiply the inverse of ‘A’ times ‘b’ using the MATLAB power operator. -E M<% :;1)#C $#I#<#(0 1( %:A>(? !;"<<#;0 %>#:#0;1#(0 ;0$ =;2GK<"=<1#1"1#(0 D#15("1 '#0$#0B 15%

#0I%)<% #1<%>'E 45#< #< =? ';) 1he most efficient method. MATLAB uses the backslash ‘ w’ to indicate:;1)#C $#I#<#(0E

f & P8 LC H N9QC 5 & PFC NFQC ' & 3$4DfIE5C ' & fJN8E5C ' & ft5C

Page 82: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 82/101

i)(=>%:< <1;1%:%01< D#>> ('1%0 B#I% 15% %O";1#(0< #0 <(:% <1);0B% :;00%) #0 ;0 ;11%:A1 1(2(0'"<% ?("E 6;G% <")% ?(") 1D( :;1)#2%< ;)% <%1 "A %C;21>? ;< #0 15% %C;:A>% ;=(I%E

%7/K# D,55,):.

674879 5;< (0% #:A()1;01 '"021#(0 '() '#11#0B ; A(>?0(:#;> 2")I% 1( ; 2(>>%21#(0 (' $;1; A(#01<Ei(>?'#1UV 1;G%< #0 ; I%21() (' CKI;>"%<F ; I%21() (' 2())%<A(0$#0B ?KI;>"%<F ;0$ 15% $%B)%% (' 15%A(>?0(:#;> ?(" D#<5 1( '():E /1 ("1A"1< 15% 2(%''#2#%01< (' <;#$ A(>?0(:#;>E

45% 15#)$ #0A"1 :;? )%O"#)% <(:% $#<2"<<#(0E 45% 0":=%) ?(" #0A"1 D#>> =% %O";> 1( 15% 5#B5%<1K()$%) %CA(0%01 #0 15% )%<">1#0B A(>?0(:#;> UY '() O";$);1#2F - '() 2"=#2F %12EVE H(D%I%)F ;0? A(>?0(:#;>2;0 5;I% ; 2(0<1;01 2(%''#2#%01 ;< D%>> ;< ; 2(%''#2#%01 '() %I%)? A(D%) (' 15% #0$%A%0$%01 I;)#;=>%F <(#0A"11#0B ; 15)%% D#>> ;21";>>? B#I% ?(" ; I%21() (' >%0B15 '(")E k7 9 * el )%A)%<%01< 7C- T 9CY T *C T eE

We’ll use some contrived data as an example:

' & O(!C ) & 'BJF N 'BJL 7 ' N 8C <.122 & =.6)23;D'M)MFI <.122 & P8 N8 8 N8Q

674879 2;0 "<";>>? :;G% )%;<(0;=>% '#1< '() ; I;)#%1? (' $#''%)%01 5#B5%<1 ()$%) 2(%''#2#%0125(#2%<E 6;15%:;1#2;>>?F 15% 5#B5%<1 ()$%) A(<<#=>% 1( A)($"2% ; "0#O"% '#1 #< (0% >%<< 15;0 15% >%0B15 (15% $;1;—; 5#B5%) ()$%) '#1 D(">$ 0(1 5;I% ; <"''#2#%01 0":=%) (' A(#01< 1( B( 15)("B5E 7< ;0 %C;:A>%F2(0<#$%) ; <#:A>% <?<1%: (' 1D( A(#01<E S(" 2(">$ '%;<#=>? A>(1 ;0 #0'#0#1% 0":=%) (' A;);=(>;< 15)("B515(<% 1D( A(#01<F ="1 (0>? (0% >#0%E

O&?6K(?HI

Q=I#("<>?F ; I%21() (' 2(%''#2#%01< #< 0(1 I%)? "<%'"> #' ?(" D;01 1( %I;>";1% 15% '"021#(0 ;1 (15%)A(#01<E _()1"0;1%>?F D% 5;I% 15% A(>?I;>UV '"021#(0 1( '#C 15;1 A)(=>%:E

i(>?I;>UV 1;G%< #0 ; I%21() (' 2(%''#2#%01< )%A)%<%01#0B ; A(>?0(:#;> %O";1#(0 ;0$ ; I%21() (' CKI;>"%< ;1 D5#25 1( %I;>";1% 15% '"021#(0E /1 ("1A"1< 15% ;<<(2#;1%$ ?KI;>"%< =;<%$ (0 15% #0A"1 '"021#(0E

M<#0B A(>?'#1UV ;0$ A(>?I;>UV 2;0 =% "<%$ #0 2(0@"021#(0 1( 2(0I%)1 ; 2(>>%21#(0 (' $#<2(00%21%$A(#01< #01( ; '"021#(0 ;0$ %I;>";1% 15% '"021#(0 ;1 :()% A(#01< 1( A)($"2% ; <:((15 A>(1E

' & 8(!C ) & P8BF LB* FBL HB9 !BUQC =6.;D'M)Mr-ErI <.122 & =.6)23;D'M)MHIC '3 & 63$%=#<1DOM!IC )3 & =.6)4#6D<.122M'3IC >.60 .$

Page 83: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 83/101

=6.;D'3M)3I ;3;61Dr^1@-1%%3.$ /%3$@ =.6)23;DI #$0 =.6)4#6DIrI

A)5#/2UHI.

Don’t forget the numerical ‘1’ at the end of this function name. Interp() is a completely different'"021#(0 15;1 #< 0%I%) "<%$ #0 *+ ,-.,E /01%)A(>;1#(0 ;>>(D< ?(" 1( %<1#:;1% 15% I;>"%< ;1 A(#01< #0=%1D%%0 #0$#I#$";> $;1; A(#01< =? 2(00%21#0B 15%: D#15 <1);#B51 >#0%<E 8#0%;) #01%)A(>;1#(0 $(%< JQ4A)($"2% <:((15 2")I%< =;<%$ (0 $;1; 1)%0$<L #1 :%)%>? 2(00%21< %;25 <%1 (' 1D( A(#01< D#15 ; <1);#B51>#0%E

45% #0A"1< '() #01%)A, ;)% ; I%21() (' CKI;>"%<F ; I%21() (' ?KI;>"%<F ;0$ ; I%21() (' 0%D CKI;>"%<;1 D5#25 ?(" D#<5 1( #01%)A(>;1%E /01%)A,UV ("1A"1< 15% %<1#:;1%$ ?KI;>"%< '() 15(<% 0%D CKI;>"%<E

' & 8(!C ) & P8BF LB* FBL HB9 !BUQC =6.;D'M)Mr-ErI >.60 .$ '3 & 63$%=#<1DOM!IC )3 & 3$;1-=8D'M)M'3IC =6.;D'3M)3I ;3;61Dri$;1-=.6#;3.$ /%3$@ 3$;1-=8DIrI

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-6

-4

-2

0

2

4

6Regression using polyfit() and polyval()

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 51

1.5

2

2.5

3

3.5

4

4.5

5

5.5

6Interpolation using interp1()

Page 84: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 84/101

/01%)A,UV 2;0 ;><( =% "<%$ '() %C1);A(>;1#(0E RC1);A(>;1#(0 #< 15% A)(2%<< (' B"%<<#0B 15% ?KI;>"%(' ; $;1; A(#01 ("1<#$% 15% #0#1#;> $;1; );0B%E 7< <"25F %C1);A(>;1#(0 #< ('1%0 I%)? "01)"<1D()15? =%2;"<%15%)% #< 0( D;? (' ;22");1%>? %<1#:;1#0B 1)%0$< ("1<#$% (' ; B#I%0 $;1; );0B%E 674879 ;AA%;)< 1( 5;I%25;0B%$ 15#< A;)1#2">;) '"021#(0 #0 #1< 0%D%<1 ;$$#1#(0F <( %C1);A(>;1#(0 0(D )%O"#)%< '#I% #0A"1<E

)3 & 3$;1-=8D'M)M'3Mr63$1#-rMr1';-#=rIC

Don’t use extrapolation.

>2?,)#HI.

+A>#0%UV #< ;0 ($$ '"021#(0 15;1 #< 2(0'"<#0B '() :(<1 A%(A>%F ="1 #1 #< '()1"0;1%>? )%>;1#I%>?"0#:A()1;01E +A>#0%UV #< "<%$ 1( ;25#%I% 0(0>#0%;) #01%)A(>;1#(0 =;<%$ (0 A#%2%D#<% 2"=#2 '"021#(0<E9;<#2;>>?F #1 1;G%< %I%)? <%1 (' 15)%% A(#01< ;0$ "<%< <(:% <()1 (' <A%2#;> 674879 1)#2G 1( 2(00%21 15%:

D#15 ; 2"=#2 '"021#(0E +A>#0% #01%)A(>;1#(0< ;>D;?< B( 15)("B5 %I%)? A(#01E

' & 8(!C ) & P8BF LB* FBL HB9 !BUQC =6.;D'M)Mr-ErI >.60 .$ '3 & 63$%=#<1DOM!IC )3 & %=63$1D'M)M'3IC =6.;D'3M)3I ;3;61Dri$;1-=.6#;3.$ /%3$@ %=63$1DIrI

/1 >((G< ; >(1 >#G% 15% A(>?I;>UV A>(1E

8,JJ#/#)5,(5,&) ()* A)5#:/(5,&) &J O&?6)&',(?1.

9%2;"<% 15% $%)#I;1#I%< ;0$ #01%B);>< (' A(>?0(:#;>< ;)% =;<%$ (0>? (0 ; <#:A>%F %;<? '():">;FD% 2;0 "<% 674879 1( A)($"2% 15% 2(%''#2#%01< I%)? O"#2G>?E 45% <%2)%1 #< 1( 2)%;1% ; I%21() (' %CA(0%01I;>"%<F >#G% k- Y , jl '() ; 2"=#2 '"021#(0 ;0$ "<% #1 1( :">1#A>? () $#I#$% 15% ()#B#0;> 2(%''#2#%01<Ea%:%:=%) 15% =;<#2 '():">;<3

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-3

-2

-1

0

1

2

3

4

5

6Interpolation using spline()

Page 85: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 85/101

() = = +1+

+( '() $#''%)%01#;1#(0 D% :">1#A>? %;25 2(%''#2#%01 =? #1< 2())%<A(0$#0B %CA(0%01 ;0$ $%>%1% 15%>;<1 (0% U)%:%:=%) 15;1 15% $%)#I;1#I% (' ; 2(0<1;01 #< N%)(VE P% #01%B);1% =? $#I#$#0B %;25 2(%''#2#%01=? #1< 2())%<A(0$#0B %CA(0%01 A>"< (0% ;0$ ;$$#0B ;0 ;)=#1);)? 2(0<1;01 U"<";>>? N%)(V 1( 15% %0$E*(0<#$%) 15% '"021#(0 'UCV h `C- T -CY – YC T ,E

<.122 & P! F NL 8QC 01- & <.122BED61$@;>D<.122IN8(N8(OIC 01-D1$0I & PQC 3$; & <.122 BG D61$@;>D<.122I(N8(8IC 3$;D1$078I & OC

8,JJHI.

45% $#''UV '"021#(0 1;G%< #0 ; I%21() ;0$ ("1A"1< 15% $#''%)%02%< =%1D%%0 %;25 <%1 (' 1D(%>%:%01< #0 15% I%21()E 45% >%0B15 (' 15% ("1A"1 I%21() D#>> ;>D;?< =% (0% >%<< 15;0 15% >%0B15 (' 15%()#B#0;> I%21()E e#''UV #< 0(1 Iery useful but can be used with ‘xy’ data to estimate the derivate dy/dx at:">1#A>% A(#01<E

' & P8 L ! T 8FQC ) & PN8 ! L N8O !QC 0322D'I #$% & P8 F F !Q 0322D)IBG 0322D'I #$% & P* N8 NH FQ

%7'17'HI.

70(15%) '"021#(0 D#15 )%>;1#I%>? >#11>% A);21#2;> "<%F 2":<":UV 1;G%< #0 ; I%21() ;0$F '() %;25%>%:%01F ("1A"1< 15% <": (' 15;1 %>%:%01 ;0$ ;>> A)%I#("< %>%:%01<E 45% ("1A"1 I%21() #< (' 15% <;:%>%0B15 ;< 15% #0A"1 I%21()E

' & P8 L ! T 8FQC </A%/AD'I #$% & P8 F T 8* LUQ

Page 86: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 86/101

!/(2THI ()* %7'5/(2THI.

4);ANUV A)(I#$%< ;0 %<1#:;1% (' 15% 0":%)#2;> #01%B);> (' ; <%1 (' A(#01< U15% ;)%; =%0%;15 15%curve) by using the trapezoidal approximation from calculus. If you don’t remember the details aboutthe trapezoidal approximation, don’t worry—it’s not very im A()1;01E 4);ANUV 1;G%< #0 QJ8S QJR I%21()F

15% <%1 (' ?KI;>"%<F ;0$ <%%:< 1( ;<<":% %I%0 <A;2#0B =%1D%%0 15%:E 45% ("1A"1 #< ; <#0B>% 0":=%)F15% %<1#:;1#(0 (' 15% $%'#0#1% #01%B);>E

*":1);ANUV D()G< :"25 >#G% 2":<":UV #0 15;1 #1 ("1A"1< 15% <": (' 15% 2"))%01 1);A%N(#$ ;>(0BD#15 ;>> A)%I#("< (0%< '() %;25 %>%:%01 #0 15% I%21()E 45% ("1A"1 D#>> ;><( =% (' 15% <;:% >%0B15 ;< 15%#0A"1 I%21()E 45% '#)<1 %>%:%01 (' 15% ("1A"1 #< ;>D;?< N%)(F ;0$ 15% >;<1 %>%:%01 #< ;>D;?< %O";>< 15%1(1;> ;AA)(C#:;1#(0 B#I%0 =? 15% 1);ANUV '"021#(0E

) & P8 L ! T 8FQC ;-#=dD)I #$% & LL </A;-#=dD)I #$% & PO 8B! ! 88B! LLQ

That’s pretty much it for numerical methods; most of these functions have very little practicalI;>"% ;0$ D#>> A)(=;=>? =% #B0()%$ (0 5(:%D()G ;0$ 1%<1 A)(=>%:<E 6(<1 0":%)#2;> :%15($< A)(=>%:<;)% )%>;1#I%>? <1);#B51'()D;)$E 7>D;?< )%:%:=%) 5(D 1( "<% 15% >#0<A;2%UV '"021#(0E

<1#J7? D7)35,&)1.

A(>?'#1UCF?F()$%)V—("1A"1< 15% 2(%''#2#%01< (' 15% =%<1K'#1 A(>?0(:#;> D#15 5#B5%<1 %CA(0%01equal to ‘order’

A(>?I;>U2(%''FC#V—("1A"1< 15% ?Kvalues of the function given by the coefficients in ‘coeff’ at allpoints in ‘xi’

#01%)A,UCF?FC#V—"<%< >#0%;) #01%)A(>;1#(0 1( ;AA)(C#:;1% 15% ?Kvalues at ‘xi’ <A>#0%UCF?FC#V—"<%< <A>#0% U<1);0B% 2"=#2V #01%)A(>;1#(0 1( ;AA)(C#:;1% 15% ?Kvalues at ‘xi’ $#''UI%2V—calculates the difference between every pair of elements in ‘vec’ 2":<":UI%2V —("1A"1< 15% <": (' %;25 %>%:%01 A>"< ;>> A)%I#("< (0%< 1);ANU?V—%<1#:;1%< 15% 0":%)#2;> #01%B);> (' 15% ?KI;>"%< "<#0B 1);A%N(#$;> ;AA)(C#:;1#(0 2":1);ANU?V—("1A"1< 15% <": (' %;25 1);A%N(#$ A>"< ;>> A)%I#("< (0%<F "<#0B 1);A%N(#$;>

;AA)(C#:;1#(0

Page 87: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 87/101

+%21#(0 ,.3 +("0$

+("0$ #< 15% >;<1 5(:%D()G 1(A#2 ;0$ #< "<";>>? <(:%D5;1 $#''#2">1 '() A%(A>% 1( B);<A

2(02%A1";>>?F ;>15("B5 15% ;21";> 674879 2($#0B #< ';#)>? <1);#B51'()D;)$E 674879 2;0 =% "<%$ 1( )%;$#0 ;0$ :;0#A">;1% <("0$F :"25 >#G% #:;B%<E

7>:(<1 ;>> 2($#0B D#15 <("0$ #0I(>I%< %C%2"1#0B ; <A%2#'#2 <%)#%< (' 2(::;0$< 1( A%)'(): ; 1;<GE6;0? (' 15%<% ;>B()#15:< ;)% $#''#2">1 1( "0$%)<1;0 d, by which I mean that I don’t understand them. You<5(">$ =% '#0% #' ?(" @"<1 :%:()#N% 15%:E

+(K/#(*HI.

P;I)%;$UV )%;$< #0 <("0$ '#>%< ')(: ?(") 2"))%01 $#)%21()?E 45% #0A"1 #< 15% '#>%0;:%F ; <1)#0BE45% '#)<1 ("1A"1 #< 15% <("0$ #1<%>' <1()%$ #0 ;%;C<BP I%21()E 45#< I%21() 2(01;#0< 15% ;:A>#1"$% I;>"%<U<;:A>%<V '() 15% <("0$ #0 1?A% $("=>%—5#B5%) 0":=%)< )%A)%<%01 >("$%) <("0$<E 45% <%2(0$ ("1A"1 #<15% <;:A>#0B ')%O"%02?F 15% );1% ;1 D5#25 15% ;:A>#1"$% I%21() #< )%;$ =? 674879 #0 <;:A>%< A%)<%2(0$E /' ?(" A)%'%) :"<#2;> 1%):#0(>(B?F 15#0G (' <;:A>#0B ')%O"%02? ;< 15% 1%:A( (' 15% <("0$Ei>%;<% 0(1#2% :? <("0$ 0(1;1#(0 =%'()% #1 2(0'"<%< ?(" >;1%)F ;0$ 0%I%) '()B%1 1( <"AA)%<< 15#< '"021#(0E

P0#;#M 2%Q & ?#4-1#0D2$IC

=(1,3 9?:&/,5"'1.

/ D#>> B#I% ; =)#%' %CA>;0;1#(0 '() %;25 (' 15%<%L #' ?(" '()B%1 15% 2($%F ?(" 2;0 A)(=;=>? '#B")% #1("1 >(B#2;>>?E

J":=%) (' <;:A>%< —%I%)? %>%:%01 #0 15% ;:A>#1"$% I%21() )%A)%<%01< (0% <;:A>%E0": h >%0B15U$;1;VL

Δt, the time per sample— #' 15% <;:A>#0B ')%O"%02? B#I%< "< <;:A>%< A%) <%2(0$F #1< #0I%)<%:"<1 =% <%2(0$< A%) <;:A>%E$1 h ,W'<L

45% $");1#(0 (' 15% <("0$ —now that we have ‘dt’, we can multiply seconds per sample times15% 1(1;> 0":=%) (' <;:A>%< 1( 2;>2">;1% 15% 1(1;> $");1#(0 #0 <%2(0$<E$") h $1]0":L

45% :;C#:": A(<<#=>% <;:A>#0B ')%O"%02? '() 15% ;:A>#1"$% I%21() —there’s some weird2(02%A1 2;>>%$ 15% J?O"#<1 45%()%: 15;1 / A)(=;=>? "0$%)<1(($ ;1 (0% A(#01E /1 <;?< 15;1 15%:;C#:": ')%O"%02? #< %O";> 1( 5;>' (' 15% B#I%0 <;:A>#0B ')%O"%02?E'[0?O"#<1 h '<WYL

Page 88: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 88/101

45% <("0$ A>;?%$ #0 )%I%)<%—15#< #< @"<1 =;<#2 #0$%C#0B (' I%21()<E)%I%)<% h $;1;U%0$3K,3,VL

45% ';<1 '(")#%) 1);0<'(): (' 15% <("0$ —this is another idea that I don’t understand. Luckily,15% 47< "<";>>? A(<1 ; B"#$% '() 15% ''1UV '"021#(0 #< 674879F D5#25 ?(" 2;0 )%;$ #' ?(" 5;I% 15%1#:% =%'()% '#0;><E a%:%:=%) 1( 1;G% 15% ;=<(>"1% I;>"%F :">1#A>? =? 1D(F $#I#$% =? 15% >%0B15(' 15% $;1;F ;0$ $%>%1% 15% <%2(0$ 5;>' (' 15% )%<">1E__4 h Y];=<U''1U$;1;VVW>%0B15U$;1;VL__4 h __4U,3)("0$U%0$WYVVL

%"():,): 5"# O,53" &J ( >&7)*.

45%)% ;)% 1D( :;#0 :%15($< 1( :;G% ; <("0$ 5#B5%) () >(D%)E a%:%:=%) 15;1 15#< #<'"0$;:%01;>>? $#''%)%01 ')(: 25;0B#0B 15% I(>":%F D5#25 D% D(">$ ;22(:A>#<5 =% <#:A>? ;$$#0B 1( ()

<"=1);21#0B ')(: 15% ;:A>#1"$% I%21()E

_#)<1F D% 2;0 25;0B% 15% <;:A>#0B ')%O"%02?E e("=>#0B 15% ')%O"%02? );#<%< 15% A#125 =? (0%(21;I%F D5#>% 5;>I#0B 15% ')%O"%02? $%2)%;<%< 15% A#125 =? (0% (21;I%E M0'()1"0;1%>?F $(#0B <( D#>>;''%21 15% 1(1;> $");1#(0 (' 15% <("0$F D5#25 #< 0(1 ;>D;?< $%<#);=>%E

2% & 2%ELE$C h?>1-1 $ 3% ;>1 $/A51- .2 .<;#41% 5) ?>3<> ;>1 =3;<> 3% -#3%10.- 6.?1-10

+%2(0$F D% 2;0 "<% 15% <;:% :%15($ D% "<%$ D#15 #:;B%< 1( #0$%C 15% <("0$ I%21() ;1 2%)1;#0#01%)I;>< 1( ;)1#'#2#;>>? ;''%21 15% );1% ;1 D5#25 <;:A>%< ;)% 25(<%0E 45#<F 1((F D#>> =? $%'#0#1#(0 #02)%;<%

() $%2)%;<% 15% $");1#(0 (' 15% <("0$E

0#;# & 0#;#D-./$0D63$%=#<1D8M$/AM$/AGLJD$G8LIIIIC h?>1-1 $ 3% ;>1 $/A51- .2>#62N%;1=% 5) ?>3<> ;>1 =3;<> 3% -#3%10 .- 6.?1-10B

9%2;"<% 15%<% :%15($< ;''%21 15% 1(1;> $");1#(0 (' 15% <("0$F A)(=>%:< D#>> B%0%);>>? ;<G ?("1( 1)"02;1% () N%)(K'#>> 15% ;:A>#1"$% I%21() 1( $%2)%;<% () #02)%;<% 15% '#0;> $");1#(0F )%<A%21#I%>?E45"<F 1( :;#01;#0 15% <;:% 0":=%) (' <;:A>%< ;'1%) 1);0<A(<#1#(03

2/$<;3.$ 0#;# & ;-#$%=.%1K%./$0D2$M$I

P0#;#M 2%Q & ?#4-1#0D2$IC

$/A & 61$@;>D0#;#IC

0/- & $/AG2%C

0#;# & 0#;#D-./$0D63$%=#<1D8M$/AM$/AGLJD$G8LIIIIC

$1?K0/- & 61$@;>D0#;#IG2%C

Page 89: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 89/101

32 $1?K0/- W 0/-

0#;# & 0#;#D8($/AIC

16%132 $1?K0/- X 0/-

0#;#D$/AI & OC

1$0

1$0

=(1,3 B71,3(? V(/:&).

i#125—the frequency of the sound. Higher pitches sound “higher.” J(1% —; <("0$ A)($"2%$ =? ; <#0B>% A#125E 45% <%I%0 0;1");> 0(1%< ;)% 7F9F*FeFRF_F ;0$ !E

Q21;I%—; <%)#%< (' %#B51 0(1%<F <1;)1#0B ;0$ %0$#0B D#15 15% <;:% (0%E Q21;I%< (0 15% A#;0(;)% >;=%>%$ D#15 0":=%)<F D#15 *Z =%#0B 15% * 2>(<%<1 1( 15% 2%01%) (' 15% A#;0(E 7 *` #< (0%(21;I% 5#B5%) 15;0 ; *ZF <( ;0 %C;:A>% (' ;0 (21;I% D(">$ =% *Z 1( *`E

P5(>% <1%A—15% $#''%)%02% #0 A#125 =%1D%%0 1D( 0;1");> 0(1%<F <"25 ;< e ;0$ RF #< $%'#0%$ ;< ;D5(>% <1%AE

H;>'K<1%A—<(:% 0(1%< ';>> #0 =%1D%%0 D5(>% <1%A<E 45%<% ;)% 2;>>%$ ;22#$%01;><F ;0$ ;)%$%0(1%$ =? <5;)A< UxV ;0$ '>;1< U=VE 45% $#''%)%02% #0 A#125 =%1D%%0 ; 0;1");> 0(1% ;0$ 15%0%;)%<1 <5;)A () '>;1 #< $%'#0%$ ;< ; 5;>'K<1%AE 45"<F 15%)% ;)% 1D( 5;>'K<1%A< #0 ; D5(>% <1%AE 7*x #< (0% 5;>'K<1%A 5#B5%) 15;0 ; *F D5#>% ; *= #< (0% 5;>'K<1%A >(D%) 15;0 ; *E 6"<#2;>>?F 15% 5;>'K<1%A =%1D%%0 ;0? 1D( 0;1");> 0(1%< 2;0 =% $%0(1%$ =? %#15%) 15% '>;1 () 15% <5;)A—15%? ;)%15% <;:% 0(1%E 45"<F R= ;0$ ex ;)% 1%):%$ +(*,*-+! F ;0$ ;)% %C;21>? 15% <;:% A#125E 45% (0>?%C2%A1#(0< 1( 15#< )">% ;)% 9xF *=F RxF ;0$ _=L ; 9x #< #<(1(0#2 D#15 ; *F D5#>% ; *= #< #<(1(0#2 D#15; 9E 9;<#2;>>?F 15%)% #< 0( 5;>'K<1%A =%1D%%0 * ;0$ e () =%1D%%0 R ;nd F. Here’s another greatA#21")% ')(: P#G#A%$#; 1( #>>"<1);1% 15#< 2(02%A1E

Page 90: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 90/101

*5()$ —; B)("A (' 0(1%< A>;?%$ <#:">1;0%("<>? 15;1 =>%0$ 1( A)($"2% ; :()% #01%)%<1#0B A#125E

Q#)#/(5,): %"&/*1.

+"AA(<%$>?F ?(" 2;0 B%0%);1% 25()$< #0 674879 =? <#:A>? ;$$#0B 1(B%15%) 15% ;:A>#1"$%I%21()< '() 15% $#''%)%01 0(1%<E M0'()1"0;1%>?F 15% %C;:A>%< B#I%0 #0 15#< 2(")<% "<";>>? #0I(>I% ; <%)#%<of irritating beeping noises that the Tas term a “chord.” Real chords are actually pleasing to the ears.

O?&55,): DD! K1W P&/'(?,T#* D/#X7#)36.

Once again, I don’t know what FFT is. For this problem, we use the FFT algorithm described;=(I% 1( B%0%);1% 15% ?$;1; '() 15% A>(1E 45% C$;1; D#>> =% ; <%)#%< ; I;>"%< );0B#0B ')(: j 1( 15%0?O"#<1 ')%O"%02?F ;><( $%<2)#=%$ ;=(I%E P% "<% >#0<A;2%UV 1( B%0%);1% ; I%21() (' C$;1; %O";> #0 >%0B151( 15% ?$;1;E

_#0;>>?F A)(=>%:< D#>> ('1%0 ;<G ?(" 1( #$%01#'? 15% A)#02#A;> ')%O"%02? (' ; <("0$F D5#25 #<<#:A>? 15% ')%O"%02? D#15 15% 5#B5%<1 __4 I;>"%E

2/$<;3.$ p6.;D0#;#I

) & LE#5%D22;D0#;#IIG61$@;>D0#;#IC

) & )D-./$0DD8(1$0GLIIIC

2K$)_/3%; & 2%GLC

' & 63$%=#<1DOM2K$)_/3%;M61$@;>D)IIC

=6.;D'M)I

Page 91: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 91/101

>.60 .$

P`#'M3$01'Q & A#'D)IC

2K=-3$<3=#6 & 'D3$01'IC

=6.;D2K=-3$<3=#6M `#'M r-ErI

1$0

+(K-/,5#HI.

45% (AA(<#1% (' D;I)%;$E P;ID)#1%UV 1;G%< #0 ;0 ;:A>#1"$% I%21()F ; <;:A>#0B ')%O"%02?F ;0$ ;'#>%0;:% ;0$ 2)%;1%< 15% ;AA)(A)#;1% ED;I '#>%E P;ID)#1%UV #< 15% (0>? D)#1#0B '"021#(0 #0 D5#25 15%

'#>%0;:% 2(:%< 87+4F 0(1 '#)<1E 4)? 1( )%:%:=%) 15;1 '() 15% '#0;>F ;< #1 #< I%)? 1)#2G?E

?#4?-3;1D0#;#M2%M2$I

There isn’t really too much to know for sound. Keep in mind that the sound plotting problemD#15 15% ''1UV '"021#(0 #< ; XRaS A(A">;) 2($#0B A)(=>%: (0 15% '#0;> %C;:E / 5;I% <%%0 #1 A(A "A '() 1D(2(0<%2"1#I% <%:%<1%)< 0(DE

Page 92: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 92/101

+%21#(0 ,c3 +()1#0B

+()1#0B 2(0<1#1"1%< (0% () 1D( $;?< (' >%21")% ;1 15% %0$ (' 15% <%:%<1%)F (0% A(#01>%<< $;? ('

)%2#1;1#(0F ;0$ ; <#0B>% :">1#A>% 25(#2% O"%<1#(0 (0 15% '#0;> %C;:E P5#>% <()1#0B ;AA%;)< 1( 1;G% A>;2%#0<1;01>? #0 674879 D#15 15% <()1UV '"021#(0F #1 #< ;21";>>? ; 2(:A>%C #1%);1#I% A)(2%<< 15;1 2;0 =%;22(:A>#<5%$ #0 :;0? $#''%)%01 D;?<E +()1#0B #0 *+ ,-., #0I(>I%< "0$%)<1;0$#0B ;0$ >%;)0#0B 1()%2(B0#N% '(") (' 15%<% <()1#0B :%15($<—?(" D#>> JQ4 5;I% 1( 2($% ;0? (' 15%<% :%15($<E

A)1#/5,&) >&/5.

45% <#:A>%<1 ;0$ :(<1 (=I#("< <()1#0B :%15($F #0<%)1#(0 <()1 #< ;><( (0% (' 15% >%;<1 %''#2#%01E/0<%)1#(0 <()1 A">>< ("1 (0% 0":=%) ;1 ; 1#:% ')(: 15% ()#B#0;> I%21() ;0$ ="#>$< 15% <()1%$ I%21()%>%:%01K=?K%>%:%01E 45% ;21";> ;>B()#15: )%O"#)%< 674879 1( #1%);1% 15)("B5 15% I%21() =%#0B ="#>1 #0()$%) 1( $%1%):#0% 15% A)(A%) >(2;1#(0 (' 15% 2"))%01 %>%:%01E

,E *)%;1% ;0 %:A1? ("1A"1 I%21()EYE a%:(I% ;0 %>%:%01 ')(: 15% "0<()1%$ I%21()E-E /1%);1#I%>? $%1%):#0% 15% %>%:ent’s location in the output vector. ZE i>;2% 15% %>%:%01 #0 15% ("1A"1 I%21()E`E a%A%;1 <1%A< Y 15)("B5 ZE

I%2 h k- , . Yl ("1 h klI%2 h k, . Yl ("1 h k-lI%2 h k. Yl ("1 h k, -l

I%2 h kYl ("1 h k, - .lI%2 h kl ("1 h k, Y - .l

2/$<;3.$ ./; & 3$%1-;3.$K%.-;D41<I32 3%1A=;)D41<I ZZ 61$@;>D41<I&&8

./; & 41<C-1;/-$

1$0 ./;D8I & 41<D8IC41<D8I & PQC?>361 e3%1A=;)D41<I

$/A & 41<D8IC41<D8I & PQC2.- 3 & 8(61$@;>D./;I

32 $/A X& ./;D3I./; & P./;D8(3N8IM$/AM./;D3(1$0IQC5-1#g

1$0 1$0 32 3&&61$@;>D./;I

./; & P./; $/AQC1$0

1$0 1$0

Page 93: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 93/101

=7NN?# >&/5.

9"==>% <()1 #< <#:#>;) 1( #0<%)1#(0 <()1 #0 15;1 #1 )%O"#)%< <1%AK=?K<1%A #1%);1#(0 15)("B5 15% %01<1;)1#0B I%21()E 45% $#''%)%02% #< 15;1 ="==>% <()1 A)($"2%< 15% ("1A"1 =? )%A%;1%$>? <D;AA#0B <#$%K=?K<#$% %>%:%01< #0 15% <1;)1#0B I%21() #0<1%;$ (' 2)%;1#0B ; 0%D (0%E

,E 4;G% 15% '#)<1 %>%:%01 #0 15% "0<()1%$ I%21()EYE /' #1 #< B)%;1%) 15;0 15% %>%:%01 (0 #1< )#B51F <D;A #1 D#15 15% %>%:%01 (0 #1< )#B51E-E a%A%;1 <1%A Y "01#> 15% %>%:%01 #< 0( >(0B%) B)%;1%) 15;0 15% %>%:%01 (0 #1< )#B51EZE a%A%;1 <1%A< , 15)("B5 - "01#> 15% I%21() #< <()1%$E

45#< (0% #< 1("B5 1( I#<";>#N%F D5#25 #< (02% ;B;#0 D5? D% 5;I% P#G#A%$#;3

D,/15 O(11. UY U Z Y c V UU Y Z Y c VF H%)%F ;>B()#15: 2(:A;)%< 15% '#)<1 1D( %>%:%01<F ;0$ <D;A< 15%:EU ,

Y Z

Y c V U ,Z

Y

Y c VF +D;A <#02% ` m ZU , Z Y [ c V U , Z[ Y c VF +D;A <#02% ` m YU , Z YY S V U , Z YY S VF J(DF <#02% 15%<% %>%:%01< ;)% ;>)%;$? #0 ()$%) Uc m `VF ;>B()#15: $(%< 0(1<D;A 15%:E>#3&)* O(11. UU Z Y ` c V UU Z Y ` c VU , Z [ ` c V U , [ Z ` c VF +D;A <#02% Z m YU , YZ Y c V U , YZ Y c VU , Y ZY S V U , Y ZY S V

2/$<;3.$ 41< & 5/5561K%.-;D41<I 32 3%1A=;)D41<I ZZ 61$@;>D41<I&&8

-1;/-$ 1$0 2.- 3 & 8(61$@;>D41<IN8

2.- l & L(61$@;>D41<I 32 41<DlN8I W 41<DlI

41< & P41<D8(lNLIM41<DlIM41<DlN8IM41<Dl78(1$0IQC 1$0

1$0 1$0

1$0

Page 94: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 94/101

B#/:# >&/5.

6%)B% <()1 #< ; )%2")<#I% :%15($ =;<%$ (0 15% A)#02#A>% 15;1 2(:=#0#0B 1D( <:;>>%)F A)%<()1%$I%21()< #< ';<1%) 15;0 <()1#0B 15% %01#)% 15#0B :;0";>>?E 6%)B% <()1 ;)=#1);)#>? =)%;G< 15% "0<()1%$ I%21()#01( <:;>>%) A#%2%<F <()1< 15% A#%2%<F ;0$ 15%0 :%)B%< 15%: =;2G 1(B%15%) <1%A =? <1%AE

,E e#I#$% 15% I%21() #01( 5;>I%<EYE *(01#0"% $#I#$#0B 15% 5;>I%< #01( <:;>>%) 5;>I%< "01#> ;>> A#%2%< 5;I% >%0B15 ,E-E +#:">1;0%("<>? 2(:=#0% ;0$ <()1 %;25 A;#) (' %>%:%01<EZE a%A%;1 <1%A - D#15 %;25 )%<">1#0B I%21() "01#> 15% %01#)% >#<1 #< )%="#>1E

45% A)#02#A>% (' :%)B#0B I%21()< #< 15;1F #' 15% 1D( I%21()< ;)% ;>)%;$? <()1%$F ?(" (0>? 5;I% 1(2(:A;)% 15% '#)<1 %>%:%01 #0 %;25 I%21()F 15"< <;I#0B 2(0<#$%);=>% 1#:% =? %>#:#0;1#0B %C2%<<#I%#1%);1#(0E

Page 95: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 95/101

2/$<;3.$ ./; & A1-@1K%.-;D41<I 32 3%1A=;)D41<I ZZ 61$@;>D41<I&&8

./; & 41<C 16%1

612; & A1-@1K%.-;D41<D8(-./$0D1$0GLIIIC -3@>; & A1-@1K%.-;D41<D-./$0D1$0GLI78(1$0IIC ./; & A1-@1D612;M-3@>;IC

1$0 1$0

2/$<;3.$ ./; & A1-@1D612;M-3@>;I ./; & PQC ?>361 e3%1A=;)D612;I ZZ e3%1A=;)D-3@>;I

32 e3%1A=;)D612;I YY e3%1A=;)D-3@>;I 32 612;D8I X& -3@>;D8I

./; & P./; 612;D8IQC 612;D8I & PQC

16%1 ./; & P./; -3@>;D8IQC -3@>;D8I & PQC

1$0 16%132 3%1A=;)D612;I

./; & P./; -3@>;QC -3@>; & PQC

16%1 ./; & P./; 612;QC 612; & PQC

1$0 1$0

1$0

L7,301&/5.

y"#2G<()1 #< ;0(15%) )%2")<#I% ;>B()#15: =;<%$ (0 15% #$%; (' 2(:=#0#0B A)%<()1%$ I%21()<E /1 #<<(:%D5;1 :()% %''#2#%01 15;0 :%)B% <()1F 5(D%I%)F #0 15;1 #1 <()1< 15% %>%:%01< D5#>% =)%;G#0B 15%:;A;)1 );15%) 15;0 ;'1%)D;)$E 45% O"#2G<()1 ;>B()#15: <%>%21< ; );0$(: %>%:%01 ')(: 15% "0<()1%$I%21()F 2;>>%$ 15% A#I(1F ;0$ <%A;);1%< 15% )%:;#0#0B %>%:%01< ;22()$#0B 1( D5%15%) 15%? ;)% B)%;1%)15;0 () >%<< 15;0 15% A#I(1E 45% )%<">1 (' 15#< <%A;);1#(0 #< 15;1 15% A#I(1 ;"1(:;1#2;>>? %0$< "A #0 15%2())%21 A(<#1#(0F <( )%2")<#I%>? 2)%;1#0B :()% A#I(1< %I%01";>>? <()1< 15% I%21()E

Page 96: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 96/101

2/$<;3.$ ./; & _/3<g%.-;D41<I 32 3%1A=;)D41<I ZZ 61$@;>D41<I&&8

./; & 41<C -1;/-$

1$0 61%% & PQC @-1#;1- & PQC =34.; & 41<D8IC 2.- 3 & 61$@;>D41<I(N8(L

32 41<D3I X =34.; 61%% & P61%% 41<D3IQC

16%1 @-1#;1- & P@-1#;1- 41<D3IQC

1$0 41<D3I & PQC

1$0 ./; & P_/3<g%.-;D61%%I =34.; _/3<g%.-;D@-1#;1-IQC

1$0

=,: ; G(?7#1.

Each sorting method is assigned a “big O” value based on its overall efficiency. While they are all2;A;=>% (' <()1#0B <:;>> >#<1< (' 0":=%)< I#)1";>>? #0<1;01;0%("<>?F 2(0<1;01>? #1%);1#0B 15)("B5$;1;=;0G< (' :#>>#(0< (' 0":=%)< #02")< <#B0#'#2;01 $);D=;2G< '() >%<< %''#2#%01 <()1#0B :%15($<E 45%'#)<1 1D( :%15($<F #0<%)1#(0 <()1 ;0$ ="==>% <()1F ;)% 2(0<#$%)%$ ()F :%;0#0B 15;1 15% 1#:%0%2%<<;)? 1( <()1 15% I%21() #02)%;<%< O";$);1#2;>>? D#15 15% >%0B15 (' 15% I%21()E

45% (15%) 1D( ;>B()#15:<F O"#2G<()1 ;0$ :%)B% <()1F 5;I% I;>"%< (' ( log )F :%;0#0B 15;115% #02)%;<% #0 1#:% #< >(B;)#15:#2;>>? )%>;1%$ 1( 15% >%0B15 (' 15% I%21()E 45"<F O"#2G<()1 ;0$ :%)B% <()1

;)% <#B0#'#2;01>? ';<1%) D5%0 <()1#0B >(0B%) >#<1<F '() 15% )%;<(0< %CA>;#0%$ ;=(I%E

Page 97: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 97/101

A*#)5,J6,): 5"# >&/5,): B#5"&* <1#*.

6(<1 <()1#0B A)(=>%:< #0I(>I% ;0;>?N#0B ; A#%2% (' 2($% >#G% 15% (0%< ;=(I% ;0$ #$%01#'?#0BD5#25 (' 15% '(") <()1#0B :%15($< #< =%#0B "<%$E f"<1 0(1% 15% $#''%)%02%< ;0$ '(>>(D 15#< %;<? '>(D25;)1E

7 A)(=>%: :#B51 1)? 1( 1)#2G ?(" =? "<#0B 15% :%)B% <()1 ;>B()#15: ="1 0;:#0B (0% (' 15%variables ‘pivot’, or other such tricks. Just follow the general flowchart and you should be fine.

/ ;=<1;#0%$ ')(: 2(::%01#0B ;0? (' 15% ;=(I% <()1#0B 2($%< #0 5(A%< 15;1 15%? D#>> ;AA%;)2>%;)%) ;< ; D5(>%E 6(<1 (' 15% #$%;< #0I(>I%$ ;)% ';#)>? <1);#B51'()D;)$F ;0$ #' ?(" 0%%$ <(:% '"02($#0B A);21#2% #0 #1%);1#(0 () )%2")<#(0 =%'()% 15% '#0;>F 15%<% ;>B()#15:< ;)% 5#B5>? #0<1)"21#I%E

Page 98: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 98/101

+%21#(0 ,d3 *(02>"<#(0

45;0G ?(" '() )%;$#0B :? B"#$% '() *+ ,-.,E /1 5;< =%%0 ; B)%;1 A>%;<")% 1( D()G D#15 <( :;0?

';<2#0;1#0B <1"$%01< D5#>% 2(:A>%1#0B 15#< A)(@%21F ;0$ / 5;I% B;)0%)%$ 0":%)("< ')#%0$<5#A< #0 15%A)(2%<<E / ;><( ;AA)%2#;1% 15% :;0? 15;0G< / 5;I% )%2%#I%$ =(15 A%)<(0;>>? ;0$ 15)("B5 %:;#>E

Regarding payment, please don’t offer me anything in return for this guide— 2(0<#$%) #1 :? ')%%B#'1 1( ?("E / (0>? ;<G 15;1 ?(" 2(0<#$%) 5(D :"25 A(1%01#;> ?(" 5;I% 1( :;G% ; $#''%)%02% #0 15% >#I%< ('(15%)<L 5%>A#0B A%(A>% #< ;< <#:A>% ;< =%#0B A%)2%A1#I% %0("B5 1( 0(1#2% ; A)(=>%: ;0$ 2;)#0B %0("B5 1(2())%21 #1E

45%)% ;)% :(<1 >#G%>? 2("01>%<< <:;>> 2($#0B :#<1;G%< ;0$ (15%) <"25 %))()< #0 15#< $(2":%01E /'?(" 0(1#2% ;0? <A%2#'#2 (0%<F A>%;<% >%1 :% G0(DE S(" :;? ;><( #0'(): :% (' ;0? ;$$#1#(0<F )%I#<#(0<F ()2>;)#'#2;1#(0< 15;1 :;? =% =%0%'#2#;> '() '"1")% )%;$%)< (' 15#< <1"$? B"#$%E 6? %:;#> ;$$)%<< #<G:2;))z?:;#>E2(: E

_%%> ')%% 1( $#<1)#="1% 15%<% B"#$%< 1( D5#25%I%) <1"$%01< :;? '#0$ 15%: "<%'">E / 5;I% 1)#%$ :?=%<1 1( B%0%);1% :? (D0 A);21#2% A)(=>%:< ;0$ ;I(#$ B#I#0B ;0<D%)< 1( )%;> 5(:%D()G () 1%<1A)(=>%:<F <( 15#< B"#$% <5(">$ =% 2(0<#$%)%$ ;0 5(0%<1 <(")2% (' :;1%)#;> '() 15% 2(")<%E J( (0% 5;<:? A%):#<<#(0 1( <%>> 15#< $(2":%01 () 1( )%:(I% :? 0;:% ')(: #1E

/ ;: A>;00#0B 1( %$#1 ;0$ )%I#<% 15% <1"$? B"#$% 0%C1 <%:%<1%)F :(<1 >#G%>? =? ;$$#0B ; <%A;);1%%C;:A>% <%21#(0 '() %;25 1(A#2 ;< D%>> ;< 15)%% A);21#2% %C;:< ;0$ ; A);21#2% '#0;>E /' ?(" D(">$ >#G% 15%'#0;> )%I#<%$ 2(A?F >%1 :% G0(D ;1 15% %0$ (' 0%C1 <%:%<1%)E

!"# D,)(? EF('.

45% *+ ,-., '#0;> #< 2(:A)%5%0<#I% ;0$ #< B%0%);>>? D()15 -`t (' ?(") (I%);>> B);$%E 45%)% D#>>=% 1D%01? 1( 15#)1? :">1#A>% 25(#2% 1);2#0B A)(=>%:< ;0$ 15)%% () '(") 2($#0B A)(=>%:<F #' / )%:%:=%)2())%21>?E S(" <5(">$ '#0$ 15% '#0;> <#B0#'#2;01>? %;<#%) 15;0 ;0? (' 15% #0$#I#$";> 1%<1< =%2;"<% 15% <G#>><?(" ;22":">;1% 15)("B5("1 15% 2(")<% ="#>$ (0 %;25 (15%)E

_() <1"$?#0B / <"BB%<1 )%D()G#0B ;>> 15)%% (' ?(") A)%I#("< %C;:< ;< D%>> ;< ;0? 5(:%D()GA)(=>%:< 15;1 D%)% )%>;1#I%>? <1);#B51'()D;)$ ="1 B;I% ?(" 1)("=>% 2(02%A1";>>?E 4(A#2< 1( '(2"< (0 ;)%'#>% /QF <1)"21")%<F )%2")<#(0F #:;B%<F ;0$ <("0$E

Page 99: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 99/101

7BB)%B;1% M<%'"> _"021#(0< 8#<1

8(5( !62# %&)K#/1,&).

$("=>%UCV—2(0I%)1< C 1( 1?A% $("=>%

25;)UCV—2(0I%)1< C 1( 1?A% 25;) "#01cUCV—2(0I%)1< C 1( 1?A% "#01c 2>;<<UCV—)%1")0< 15% $;1; 1?A% (' C ;< ; <1)#0B

8(5( !62# 8#5#/',)(5,&).

#<0":%)#2UCV—$%1%):#0%< #' C #< (' 1?A% $("=>% #<25;)UCV—$%1%):#0%< #' C #< (' 1?A% 25;) #<2%>>UCV—$%1%):#0%< #' C #< (' 1?A% 2%>> #<<1)"21UCV—$%1%):#0%< #' C #< ; <1)"21")%

#<>(B#2;>UCV—$%1%):#0%< #' C #< (' 1?A% >(B#2;> #<%:A1?UCV—$%1%):#0%< #' C #< ;0 %:A1? I%21()F <1)#0BF %12E

G#35&/1 ()* 9//(61.

:#0UCV – )%1")0< 15% <:;>>%<1 %>%:%01 #0 15% 2(>>%21#(0 UJ(1%3 #' 15% :#0#:": I;>"% (22")<:">1#A>% 1#:%<F :#0UV ;0$ :;CUV D#>> )%1")0 (0>? 15% '#)<1 #0<1;02%V

kI;>"%F #0$%Cl h :#0UCV – )%1")0< 15% <:;>>%<1 %>%:%01 ;>(0B D#15 #1< A(<#1#(0 0":=%) :;CUCV – )%1")0< 15% >;)B%<1 %>%:%01 #0 15% 2(>>%21#(0 kI;>"%F #0$%Cl h :;CUCV – )%1")0< 15% >;)B%<1 %>%:%01 ;>(0B D#15 #1< A(<#1#(0 0":=%) <()1UCV – <()1< 15% %>%:%01< #0 ;<2%0$#0B ()$%)

k0%DgF #0$%Cl h <()1UCV – )%1")0< C #0 ;<2%0$#0B ()$%) ;>(0B D#15 ; I%21() 2(01;#0#0B 15% A(<#1#(00":=%)< (' 15% ()#B#0;> C 1( D5#25 %;25 I;>"% 2())%<A(0$<

'>#A>)UCV – '>#A< C >%'1K1(K)#B51 '>#A"$UCV—'>#A< C 1(AK1(K=(11(: x’ – 1);0<A(<%< C U)(D I%21() 2(>":0 I%21()V :($UCF0":V – )%1")0< 15% )%:;#0$%) #' C #< $#I#$%$ =? 0": )("0$UCV – )("0$< C "A () $(D0 2%#>UCV – )("0$< C "A 1( 15% 0%C1K5#B5%<1 #01%B%) #' C #< ');21#(0;> '>(()UCV – )("0$< C $(D0 1( 15% 0%C1K>(D%<1 #01%B%) #' C #< ');21#(0;> (0%<UCF?V – 2)%;1%< ;0 ;));? (' (0%< (' $#:%0<#(0 CF? UM<% , '() C () ? 1( B%0%);1% I%21()<V N%)(<UCF?V – 2)%;1%< ;0 ;));? (' N%)(< (' $#:%0<#(0 CF?

1)"%UCF?V – 2)%;1%< ;0 ;));? (' >(B#2;> 1)"%< (' $#:%0<#(0 CF? ';><%UCF?V – 2)%;1%< ;0 ;));? (' >(B#2;> ';><%< (' $#:%0<#(0 CF? <":UCV – 2(:A"1%< 15% <": (' C A)($UCV – 2(:A"1%< 15% A)($"21 (' C '#0$U>(B#2;> %CA)%<<#(0V – B%0%);1%< ; I%21() (' ;>> #0$#2%< D5%)% 15% >(B#2;> %CA)%<<#(0 #< 1)"% >#0<A;2%U;F=F0":V—2)%;1%< ;0 %I%0>? <A;2%$ I%21() (' >%0B15 0": );0B#0B ')(: ; 1( =

Page 100: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 100/101

C&:,3(? EF2/#11,&)1.

;>>UCV – 1)"% #' %I%)?15#0B #0 C #< 1)"% ;0?UCV – 1)"% #' ;0?15#0B #0 C #< 1)"% 0(1UCV – <;:% ;< oC ()UCF?V – <;:% ;< C r ? ;0$UCF?V – <;:% ;< C q ?

>5/,):1.

0":Y<1)UCV—2(0I%)1< ; $("=>% 1( #1< 0":%)#2;> %O"#I;>%01 ;< ; <1)#0B <1)Y0":UCV—2(0I%)1< ; <1)#0B 1( #1< 0":%)#2;> %O"#I;>%01 ;< ; $("=>% <1)2:AUCF?V—$%1%):#0%< #' 1D( <1)#0B< ;)% %C;21>? #$%01#2;> <1)2:A#UCF?V—$%1%):#0%< #' 1D( <1)#0B ;)% #$%01#2;>F #B0()#0B 2;<% sprintf(str,var1,var2,…)— 2)%;1%< ; <1)#0B "<#0B I;)#;=>% <1)#0B< () $("=>%< <1)1(GUCF$%>#:#1%)V—=)%;G< "A <1)#0B C =;<%$ (0 15% >(2;1#(0 (' 15% $%>#:#1%) >(D%)UCV—2(0I%)1< C 1( >(D%)2;<% >%11%)<

"AA%)UCV—2(0I%)1< C 1( "AA%)2;<% >%11%)<

%#?? 9//(61.

0":Y2%>>UCV—A>;2%< %;25 %>%:%01 #0 C #0 ;0 #0$#I#$";> 2%>> #0 ; 2%>> ;));? 2%>>Y:;1UCV—2(0I%)1< 2%>> ;));? C 1( #1< %O"#I;>%01 $("=>% () <1)#0B ;));?

D,?# A;.

2<I)%;$U'0V—<1()%< 2<I '#>% C ;< ;0 ;));? 2<ID)#1%U'0FCV—<;I%< C ;< ; 2<I '#>% $>:)%;$U'0F$%>#:#1%)V—<1()%< $>: '#>% C ;< ;0 ;));? $>:D)#1%U'0FCF$%>#:#1%)V—<;I%< C ;< ; $>: '#>% "<#0B 15% #0A"1 $%>#:#1%) k0":F1C1F);Dl h C><)%;$U'0V—)%;$< #0 ;0 RC2%> <A)%;$<5%%1 C><D)#1%U'0FCV—<1()%< C ;< ;0 RC2%> <A)%;$<5%%1 '(A%0U'0FA%):#<<#(0V—(A%0< 15% '#>% ;0$ )%1")0< 15% '#>% 5;0$>% 'B%1>U'5V—)%1")0< 15% 0%C1 >#0% #0 15% '#>% 'B%1<U'5V—)%1")0< 15% 0%C1 >#0% #0 15% '#>%F #02>"$#0B 15% 0%C1 >#0% 25;);21%) Uw0V fprintf(fh,str,var1,var2,…)— A)#01< 15% '():;11%$ <1)#0B 1( 15% '#>% () 15% 2(::;0$ D#0$(D '2>(<%U'5V—2>(<%< 15% $%<#B0;1%$ '#>%

>5/7357/# 9//(61.

struct(field1,{…},field2,{…},…)—2)%;1%< 15% #0A"1 <1)"21")% <%1'#%>$U<;F'#%>$F0%D['#%>$V—25;0B%< ; '#%>$0;:% #0 ; <1)"21")% ):'#%>$U<;F'#%>$V—)%:(I%< ; '#%>$ ')(: ; <1)"21")% B%1'#%>$U<;F'#%>$V—)%1")0< 15% I;>"% (' 15% '#%>$ #0 15% <1)"21")% '#%>$0;:%<U<;V—)%1")0< ; 2%>> ;));? (' 15% '#%>$0;:%< #0 15% <1)"21")% #<'#%>$U<;F'#%>$V—$%1%):#0%< #' 15% '#%>$0;:% %C#<1< #0 15% <1)"21")%

Page 101: CS Matlab review guide

8/10/2019 CS Matlab review guide

http://slidepdf.com/reader/full/cs-matlab-review-guide 101/101

O?&55,):.

A>(1UCF?FA;);:%1%)<V—A>(1< 1D(K$#:%0<#(0;> $;1; ;C#<—<A%2#'#%< I;)#("< 1?A% (' ;C%< U1#B51F %O";>F <O";)%F %12EV 1#1>%U<1)V—2)%;1%< 15% A>(1 1#1>% CW?WN>;=%>U<1)#0BV—>;=%>< 15% CF?F() N ;C#< 2>' —2>%;)< 15% 2"))%01 '#B")% 5(>$ (0 —A)%I%01< 15% 2"))%01 A>(1 ')(: =%#0B (I%)D)#11%0 <"=A>(1U)(DF2(>FA>(1V—2)%;1%< B)#$< (' $#''%)%01 A>(1< A>(1-UCF?FNV—A>(1< 15)%%K$#:%0<#(0;> $;1; <")'W:%<5UCCF??FNNV—2)%;1%< <")';2% A>(1< kCCF??l h :%<5B)#$UCF?V—“meshes” two vect ()< #01( 1D( ;));?< <5;$#0B—<%1< 15% <5;$#0B '() 15% 2"))%01 A>(1 U'>;1F ';2%1%$F #01%)AV 2(>():;A —<%1< 15% 2(>() <25%:% "<%$ '() 15% 2"))%01 A>(1

A'(:#1.

#:)%;$U'0V—<1()%< ;0 #:;B% ;< ; "#01c ;));? cat(dimension,var1,var2,…)— 2(02;1%0;1%< 15% #0A"1< ;>(0B 15% <A%2#'#%$ $#:%0<#(0 #:D)#1%U'0F#:F1?A%V—<1()%< 15% "#01c ;));? ;< ;0 #:;B% #:;B%W#:<5(DU#:V—$#<A>;?< 15% #:;B% <;>%: —:? 2;1

P7'#/,3(? B#5"&*1.

A(>?'#1UCF?F()$%)V—("1A"1< 15% 2(%''#2#%01< (' 15% =%<1K'#1 A(>?0(:#;> D#15 5#B5%<1 %CA(0%01equal to ‘order’

A(>?I;>U2(%''FC#V—("1A"1< 15% ?Kvalues of the function given by the coefficients in ‘coeff’ at allpoints in ‘xi’

#01%)A,UCF?FC#V—"<%< >#0%;) #01%)A(>;1#(0 1( ;AA)(C#:;1% 15% ?Kvalues at ‘xi’ <A>#0%UCF?FC#V—"<%< <A>#0% U<1);0B% 2"=#2V #01%)A(>;1#(0 1( ;AA)(C#:;1% 15% ?Kvalues at ‘xi’ $#''UI%2V—calculates the difference between every pair of elements in ‘vec’ 2":<":UI%2V —("1A"1< 15% <": (' %;25 %>%:%01 A>"< ;>> A)%I#("< (0%< 1);ANU?V—%<1#:;1%< 15% 0":%)#2;> #01%B);> (' 15% ?KI;>"%< "<#0B 1);A%N(#$;> ;AA)(C#:;1#(0