You are on page 1of 2

7usefultipsyouwanttoknowinusingMATLABcommands

PreparedbyProfVictorTan

1. Usetheuparrowkey()toreuseormodifyacommand(especiallylongcommand).Youcan
keeppressingonthiskeytorecoverthepreviouscommandsthatyouhavetyped.
2. Youcancleanupthecommandwindowusingtheclccommand.Notethatyoucanstillrecover
thepreviouscommandsusingthe()keyafterthecleanup.
3. Itsalwaysgoodtogiveyourmatrixorcommand(whichgivesamatrixasanswer)aname.e.g.
>>B=rref(A)(insteadofjusttypingrref(A)aftertheprompt)
Ifyourealizethatyouhaveforgottentoassignanametoyourpreviouscommand,youmaystill
dosointhenextimmediatecommandpromptbytyping
>>C=ans(whereCisthenamechosenbyyou,andansisthematrixthatcomesfromthe
immediatepastcommand)
4. Allthecontentofthematricesthatyouhavenamedwillbestoredintheworkspacewindow
(seediagrambelow)
Ifyouwanttochangeafewentriesofa(huge)matrix,butdonotwanttotypethewholematrix
again,youcanlookforthenameofthatmatrixintheWorkspaceandclickonit.Anew
Variableswindowwillappearthatallowsyoutomodifytheentriesaccordingly.
Note:Ifyoutypeclearinthecommandwindow,allthematricesstoredintheworkspacewill
bedeleted.

ClickonthematrixAin theworkspacewillrevealitsentriesina
newVariableswindow,whichallowsyoutochangethevaluesof
theindividualentries.Youmayclosethewindowafteryouhave
madethenecessarychanges.

5. Youcanmerge(horizontally)twoormorematricesA,B,C,,Zallhavingthesamenumberof
rowstoformasuperaugmentedmatrixbytyping
>>[ABCZ](Nocommasorverticallinesbetweenthematrices.Thesematricescanbe
columnvectors.)

Similarly,youcanmerge(vertically)twoormorematricesA,B,C,,Zallhavingthesame
numberofcolumnstoformastackedupmatrixbytyping
>>[A;B;C;;Z]
6. Ifyoumistakenlytypeacolumnvectorvasarowvectororviceversa,insteadofretyping,you
canusethetranspose:
>>v=v(thiswillchangevfromrowtocolumn,orcolumntorow)
7. Ifyouwanttogetaspecificrow(orcolumn)ofamatrixthathasbeentyped,youcantype
>>r=A(2,:)(ThiswillgiveyouthesecondrowofA;hereristhenamechosenbyyou.)
>>c=B(:,3)(ThiswillgiveyouthethirdcolumnofB;herecisthenamechosenbyyou.)

You might also like