MATLAB快速入门国外大神的教程

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

MATLABstandsforMATrixLABoratory.Itisapowerfulnumericalcomputinglanguagecommonlyusedinengineeringandmathematics.Ifyouhaveanyfeedbackpleasefeelfreetoreachmeat@the_ozzinator,orosvaldo.t.mendoza@gmail.com.%%Codesectionsstartwithtwopercentsigns.Sectiontitlesgoonthesameline.%Commentsstartwithapercentsign.%{Multilinecommentslooksomethinglikethis%}%commandscanspanmultiplelines,using'...':a=1+2+...+4%commandscanbepassedtotheoperatingsystem!pinggoogle.comwho%Displaysallvariablesinmemorywhos%Displaysallvariablesinmemory,withtheirtypesclear%Erasesallyourvariablesfrommemoryclear('A')%Erasesaparticularvariableopenvar('A')%Openvariableinvariableeditorclc%ErasesthewritingonyourCommandWindowdiary%TogglewritingCommandWindowtexttofilectrl-c%Abortcurrentcomputationedit('myfunction.m')%Openfunction/scriptineditortype('myfunction.m')%Printthesourceoffunction/scripttoCommandWindowprofileon%turnsonthecodeprofilerprofileoff%turnsoffthecodeprofilerprofileviewer%Openprofilerhelpcommand%DisplaysdocumentationforcommandinCommandWindowdoccommand%DisplaysdocumentationforcommandinHelpWindowlookforcommand%Searchesforcommandinthefirstcommentedlineofallfunctionslookforcommand-all%searchesforcommandinallfunctions%Outputformattingformatshort%4decimalsinafloatingnumberformatlong%15decimalsformatbank%onlytwodigitsafterdecimalpoint-forfinancialcalculationsfprintf('text')%printtexttothescreendisp('text')%printtexttothescreen%Variables&ExpressionsmyVariable=4%NoticeWorkspacepaneshowsnewlycreatedvariablemyVariable=4;%SemicolonsuppressesoutputtotheCommandWindow4+6%ans=108*myVariable%ans=322^3%ans=8a=2;b=3;c=exp(a)*sin(pi/2)%c=7.3891%Callingfunctionscanbedoneineitheroftwoways:%Standardfunctionsyntax:load('myFile.mat','y')%argumentswithinparentheses,separatedbycommas%Commandsyntax:loadmyFile.maty%noparentheses,andspacesinsteadofcommas%Notethelackofquotemarksincommandform:inputsarealwayspassedas%literaltext-cannotpassvariablevalues.Also,can'treceiveoutput:[V,D]=eig(A);%thishasnoequivalentincommandform[~,D]=eig(A);%ifyouonlywantDandnotV%Logicals15%ans=010=10%ans=13~=4%Notequalto-ans=13==3%equalto-ans=131&&41%AND-ans=131||41%OR-ans=1~1%NOT-ans=0%Logicalscanbeappliedtomatrices:A5%foreachelement,ifconditionistrue,thatelementis1inreturnedmatrixA(A5)%returnsavectorcontainingtheelementsinAforwhichconditionistrue%Stringsa='MyString'length(a)%ans=8a(2)%ans=y[a,a]%ans=MyStringMyString%Cellsa={'one','two','three'}a(1)%ans='one'-returnsacellchar(a(1))%ans=one-returnsastring%StructuresA.b={'one','two'};A.c=[12];A.d.e=false;%Vectorsx=[4325371]x(2)%ans=32,indicesinMatlabstart1,not0x(2:3)%ans=3253x(2:end)%ans=325371x=[4;32;53;7;1]%Columnvectorx=[1:10]%x=12345678910x=[1:2:10]%Incrementby2,i.e.x=13579%MatricesA=[123;456;789]%Rowsareseparatedbyasemicolon;elementsareseparatedwithspaceorcomma%A=%123%456%789A(2,3)%ans=6,A(row,column)A(6)%ans=8%(implicitlyconcatenatescolumnsintovector,thenindexesintothat)A(2,3)=42%Updaterow2col3with42%A=%123%4542%789A(2:3,2:3)%Createsanewmatrixfromtheoldone%ans=%542%89A(:,1)%Allrowsincolumn1%ans=%1%4%7A(1,:)%Allcolumnsinrow1%ans=%123[A;A]%Concatenationofmatrices(vertically)%ans=%123%4542%789%123%4542%789%thisisthesameasvertcat(A,A);[A,A]%Concatenationofmatrices(horizontally)%ans=%123123%45424542%789789%thisisthesameashorzcat(A,A);A(:,[312])%Rearrangethecolumnsoforiginalmatrix%ans=%312%4245%978size(A)%ans=33A(1,:)=[]%DeletethefirstrowofthematrixA(:,1)=[]%Deletethefirstcolumnofthematrixtranspose(A)%Transposethematrix,whichisthesameas:Aonectranspose(A)%Hermitiantransposethematrix%(thetranspose,followedbytakingcomplexconjugateofeachelement)A'%ConciseversionofcomplextransposeA.'%Conciseversionoftranspose(withouttakingcomplexconjugate)%ElementbyElementArithmeticvs.MatrixArithmetic%Ontheirown,thearithmeticoperatorsactonwholematrices.Whenpreceded%byaperiod,theyactoneachelementinstead.Forexample:A*B%MatrixmultiplicationA.*B%MultipleeachelementinAbyitscorrespondingelementinB%Thereareseveralpairsoffunctions,whereoneactsoneachelement,and%theother(whosenameendsinm)actsonthewholematrix.exp(A)%exponentiateeachelementexpm(A)%calculatethematrixexponentialsqrt(A)%takethesquarerootofeachelementsqrtm(A)%findthematrixwhosesquareisA%Plottingx=0:.10:2*pi;%Createsavectorthatstartsat0andendsat2*piwithincrementsof.1y=sin(x);plot(x,y)xlabel('xaxis')ylabel('yaxis')title('Plotofy=sin(x)')axis([02*pi-11])%xrangefrom0to2*pi,yrangefrom-1to1plot(x,y1,'-',x,y2,'--',x,y3,':')%Formultiplefunctionsononeplotlegend('Line1label','Line2label')%Labelcurveswithalegend%Alternativemethodtoplotmultiplefunctionsinoneplot.%while'hold'ison,commandsaddtoexistinggraphratherthanreplacingitplot(x,y)holdonplot(x,z)holdoffloglog(x,y)%Alog-logplotsemilogx(x,y)%Aplotwithlogarithmicx-axissemilogy(x,y)%Aplotwithlogarithmicy-axisfplot(@(x)x^2,[2,5])%plotthefunctionx^2fromx=2tox=5gridon%Showgrid;turnoffwith'gridoff'axissquare%Makesthecurrentaxesregionsquareaxisequal%Setaspectratiosodataunitsarethesameineverydirectionscatter(x,y);%Scatter-plothist(x);%Histogramstem(x);%Plotvaluesasstems,usef

1 / 13
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功