matlab programming

1 answer below »
matlab programming


Introduction ThepurposeofthislabistofamiliarizestudentswiththebasicsofMatlabbyreadingthroughits documentationandtoimplementaMatlabprogramthatwilltakeaninputbitstringoflengthn>0, whichisassumedtobeencodedusingn-bittwo'scomplement,anddecodeittoabase-10integer.We willuseMatlabR2021aforthislabassignment. Part1 BeforewejumpintoanyprogramminginMatlab,youshouldfirstunderstandsomeMatlabcodethatyou mayneedforthisassignment.ForeachoftheMatlabfunctionsorprogrammingconstructsbelow,you shouldreadoverwhattheydoinMatlab'sdocumentationandpracticetheminashell.Takethe necessarytimetounderstandthesyntax,whateachthingdoesbelow,andhowtousethem. 1.variables,assignmentoperator(=),andarithmeticoperators 2.notendingaMatlabstatementwithasemicolontoshowoutput 3.endingaMatlabstatementwithasemicolontosuppressoutput 4.if,elseif,else 5.relationaloperators(==,>=,>,<=,><,~=) importantnote∶the==operatorisdifferentthanthe=operator 6.workingwithstrings(asachararrayinmatlab)∶ s='011001' n=strlength(s) s(n),s(n-1),…,s(2),s(1) s(n)=='1',s(n-1)=='1',…,s(2)=='1',s(1)=='1' 7.while 8.for 9.fprintf part2 afteryouarefamiliarwithsomematlabprogrammingfromthepreviouspart,youshouldcreateafolder (perhapsonyourdesktop)called downloadthefiledecode.mfromelc,andplacethatfilein your folder.youmayedit.mfilesinmatlaboruseasimpletexteditor.openthe.mfileand readthroughthecommentsandimplementthefunction(s)inthatfile. the.mfilecontainsthecorrectsyntax fordeclaringfunctions.forthislabassignment,donotuseanybuilt-infunctionsinmatlabthat automaticallyconvertabitstring(oranybinaryrepresentation)toaninteger(usingsuchafunctionwill resultinazeroonthisassignment).also,donotusetheflipfunctioninmatlab. incomputerscience,itiscommontorunprogramsusingcommandlinearguments.wewilldothisfor thislab'sprogram.toruntheprogramusingthecommandline,youshouldopenupacommandprompt (windows)orterminal(mac)andcdintoyour (askyourtaifyouneedhelpwiththis). wewillruntheprogramforthisassignmentwithonecommandlineargumentasshownintheexamples. afteryoufinishcorrectlyimplementingthe.mfile,yourprogram'sinputandoutputmustlooklikethe followingexamples(thisisarequirement).eachexampleisaseparaterunofacorrectlyworking program.yourprogrammustworkforanyvalidcommandlineargument,whichyoumayassumetobea bitstringoflengthn>0. examples matlab-batch"decode0"; assume0representsanintegerencodedwith1-bittwo'scomplement 0decodedasabase-10integeris0 matlab-batch"decode1"; assume1representsanintegerencodedwith1-bittwo'scomplement 1decodedasabase-10integeris-1 matlab-batch"decode00"; assume00representsanintegerencodedwith2-bittwo'scomplement 00decodedasabase-10integeris0 matlab-batch"decode01"; assume01representsanintegerencodedwith2-bittwo'scomplement 01decodedasabase-10integeris1 matlab-batch"decode10"; assume10representsanintegerencodedwith2-bittwo'scomplement 10decodedasabase-10integeris-2 matlab-batch"decode11"; assume11representsanintegerencodedwith2-bittwo'scomplement 11decodedasabase-10integeris-1 matlab-batch"decode01011001"; assume01011001representsanintegerencodedwith8-bittwo'scomplement 01011001decodedasabase-10integeris89 matlab-batch"decode11011001"; assume11011001representsanintegerencodedwith8-bittwo'scomplement 11011001decodedasabase-10integeris-39 matlab-batch"decode0100111110111"; assume0100111110111representsanintegerencodedwith13-bittwo'scomplement 0100111110111decodedasabase-10integeris2551 matlab-batch"decode1100001110111"; assume1100001110111representsanintegerencodedwith13-bittwo'scomplement 1100001110111decodedasabase-10integeris-1929 submission beforesubmittingaprogramtousforgrading,youmusttestthatyourprogramworkscorrectlywiththe examplesprovidedandotherexamplesyourunandworkoutbyhand(notprovidedinthisdocument). onceyoucorrectlyimplementanalgorithm,itshouldworkforvalidinputs. ~=")" important="" note∶="" the="=" operator="" is="" different="" than="" the="operator" 6.="" working="" with="" strings="" (as="" a="" char="" array="" in="" matlab)∶="" s='011001' n="strlength(s)" s(n),="" s(n-1),="" …,="" s(2),="" s(1)="" s(n)="=" '1',="" s(n-1)="=" '1',="" …,="" s(2)="=" '1'="" ,="" s(1)="=" '1'="" 7.="" while="" 8.="" for="" 9.="" fprintf="" part="" 2="" after="" you="" are="" familiar="" with="" some="" matlab="" programming="" from="" the="" previous="" part,="" you="" should="" create="" a="" folder="" (perhaps="" on="" your="" desktop)="" called="" download="" the="" file="" decode.m="" from="" elc,="" and="" place="" that="" file="" in="" your="" folder.="" you="" may="" edit="" .m="" files="" in="" matlab="" or="" use="" a="" simple="" text="" editor.="" open="" the="" .m="" file="" and="" read="" through="" the="" comments="" and="" implement="" the="" function(s)="" in="" that="" file.="" the="" .m="" file="" contains="" the="" correct="" syntax="" for="" declaring="" functions.="" for="" this="" lab="" assignment,="" do="" not="" use="" any="" built-in="" functions="" in="" matlab="" that="" automatically="" convert="" a="" bit="" string="" (or="" any="" binary="" representation)="" to="" an="" integer="" (using="" such="" a="" function="" will="" result="" in="" a="" zero="" on="" this="" assignment).="" also,="" do="" not="" use="" the="" flip="" function="" in="" matlab.="" in="" computer="" science,="" it="" is="" common="" to="" run="" programs="" using="" command="" line="" arguments.="" we="" will="" do="" this="" for="" this="" lab's="" program.="" to="" run="" the="" program="" using="" the="" command="" line,="" you="" should="" open="" up="" a="" command="" prompt="" (windows)="" or="" terminal="" (mac)="" and="" cd="" into="" your="" (ask="" your="" ta="" if="" you="" need="" help="" with="" this).="" we="" will="" run="" the="" program="" for="" this="" assignment="" with="" one="" command="" line="" argument="" as="" shown="" in="" the="" examples.="" after="" you="" finish="" correctly="" implementing="" the="" .m="" file,="" your="" program's="" input="" and="" output="" must="" look="" like="" the="" following="" examples="" (this="" is="" a="" requirement).="" each="" example="" is="" a="" separate="" run="" of="" a="" correctly="" working="" program.="" your="" program="" must="" work="" for="" any="" valid="" command="" line="" argument,="" which="" you="" may="" assume="" to="" be="" a="" bit="" string="" of="" length="" n="" >="" 0.="" examples="" matlab="" -batch="" "decode="" 0";="" assume="" 0="" represents="" an="" integer="" encoded="" with="" 1-bit="" two's="" complement="" 0="" decoded="" as="" a="" base-10="" integer="" is="" 0="" matlab="" -batch="" "decode="" 1";="" assume="" 1="" represents="" an="" integer="" encoded="" with="" 1-bit="" two's="" complement="" 1="" decoded="" as="" a="" base-10="" integer="" is="" -1="" matlab="" -batch="" "decode="" 00";="" assume="" 00="" represents="" an="" integer="" encoded="" with="" 2-bit="" two's="" complement="" 00="" decoded="" as="" a="" base-10="" integer="" is="" 0="" matlab="" -batch="" "decode="" 01";="" assume="" 01="" represents="" an="" integer="" encoded="" with="" 2-bit="" two's="" complement="" 01="" decoded="" as="" a="" base-10="" integer="" is="" 1="" matlab="" -batch="" "decode="" 10";="" assume="" 10="" represents="" an="" integer="" encoded="" with="" 2-bit="" two's="" complement="" 10="" decoded="" as="" a="" base-10="" integer="" is="" -2="" matlab="" -batch="" "decode="" 11";="" assume="" 11="" represents="" an="" integer="" encoded="" with="" 2-bit="" two's="" complement="" 11="" decoded="" as="" a="" base-10="" integer="" is="" -1="" matlab="" -batch="" "decode="" 01011001";="" assume="" 01011001="" represents="" an="" integer="" encoded="" with="" 8-bit="" two's="" complement="" 01011001="" decoded="" as="" a="" base-10="" integer="" is="" 89="" matlab="" -batch="" "decode="" 11011001";="" assume="" 11011001="" represents="" an="" integer="" encoded="" with="" 8-bit="" two's="" complement="" 11011001="" decoded="" as="" a="" base-10="" integer="" is="" -39="" matlab="" -batch="" "decode="" 0100111110111";="" assume="" 0100111110111="" represents="" an="" integer="" encoded="" with="" 13-bit="" two's="" complement="" 0100111110111="" decoded="" as="" a="" base-10="" integer="" is="" 2551="" matlab="" -batch="" "decode="" 1100001110111";="" assume="" 1100001110111="" represents="" an="" integer="" encoded="" with="" 13-bit="" two's="" complement="" 1100001110111="" decoded="" as="" a="" base-10="" integer="" is="" -1929="" submission="" before="" submitting="" a="" program="" to="" us="" for="" grading,="" you="" must="" test="" that="" your="" program="" works="" correctly="" with="" the="" examples="" provided="" and="" other="" examples="" you="" run="" and="" work="" out="" by="" hand="" (not="" provided="" in="" this="" document).="" once="" you="" correctly="" implement="" an="" algorithm,="" it="" should="" work="" for="" valid="">
Answered Same DaySep 12, 2022

Answer To: matlab programming

Sathishkumar answered on Sep 13 2022
72 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here