資源描述:
《matlab實訓3-字符串元胞和結(jié)構(gòu)數(shù)組》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、實訓二字符串數(shù)組、元胞數(shù)組和結(jié)構(gòu)數(shù)組2.1字符串數(shù)組2.2元胞數(shù)組(單元數(shù)組)2.3結(jié)構(gòu)數(shù)組(構(gòu)架數(shù)組)2.1字符串數(shù)組2.1.1字符串構(gòu)造>>t='Howaboutthischaracterstring?'t=Howaboutthischaracterstring?>>size(t)ans=132>>whosNameSizeBytesClasst1x3264chararrayGrandtotalis34elementsusing80bytes>>u=abs(t)u=Columns1through127211111932979811111711632116104Col
2、umns13through241051153299104971149799116101114Columns25through323211511611410511010363>>char(u)ans=Howaboutthischaracterstring?>>u=t(16:24)u=character>>u=‘Hello,';>>v=‘World!';>>v=['Characterstringshavingmorethan''onerowmusthavethesamenumber''ofcolumnjustlikematrices!']v=Characterstrings
3、havingmorethanonerowmusthavethesamenumberofcolumnjustlikematrices!>>w=[uv]w=Hello,World!>>disp(w)Hello,World!>>lengends=char(‘Wilt’,‘Russel’,‘Kareem)lengends=WiltRusselKareem>>char('one','','tow','three')ans=onetowthree>>strvcat('one','','two','three')ans=onetwothree2.1.2數(shù)字與字符串的相互轉(zhuǎn)換Dec2h
4、ex十進制數(shù)到十六進制字符串轉(zhuǎn)換fprintf把格式化的文本寫到文件中或顯示屏上hex2dec十六進制字符串轉(zhuǎn)換成十進制數(shù)hex2num十六進制字符串轉(zhuǎn)換成IEEE浮點數(shù)int2str整數(shù)轉(zhuǎn)換成字符串lower字符串轉(zhuǎn)換成小寫num2str數(shù)字轉(zhuǎn)換成字符串setstrASCII轉(zhuǎn)換成字符串sprintf用格式控制,數(shù)字轉(zhuǎn)換成字符串sscanf用格式控制,字符串轉(zhuǎn)換成數(shù)字str2mat字符串轉(zhuǎn)換成一個文本矩陣str2num字符串轉(zhuǎn)換成數(shù)字upper字符串轉(zhuǎn)換成大寫>>rad=2.5;area=pi*rad^2;>>t=['Acircleofradius'num2str(r
5、ad)…'hasanareaof’num2str(area)'.'];>>disp(t)Acircleofradius2.5hasanareaof19.63>>t=sprintf('Acircleofradius%.4ghasanareaof%.4g.’…,rad,area);>>disp(t)Acircleofradius2.5hasanareaof19.63.>>fprintf('Acircleofradius%.4ghasanareaof%.4g.‘…,rad,area)Acircleofradius2.5hasanareaof19.63.fprintf與sp
6、rintf的區(qū)別是,前者把轉(zhuǎn)換結(jié)果書寫于屏幕或指定的文件,而后者則是把轉(zhuǎn)換結(jié)果存放于變量fprintf('%.0e',pi)3e+00fprintf('%.3e',pi)3.142e+00fprintf('%.10e',pi)3.1415926536e+00fprintf('%.0f',pi)3fprintf('%.3f',pi)3.142fprintf('%.10f',pi)3.1415926536fprintf('%.0g',pi)3fprintf('%.3g',pi)3.14fprintf('%.10g',pi)3.141592
7、654fprintf('%.8.0g',pi)3fprintf('%.8.3g',pi)3.14fprintf('%.8.10g',pi)3.1415926542.1.3字符串函數(shù)eval(string)作為一個MATLAB命令求字符串的值blanks(n)返回一個n個零或空格的字符串deblank去掉字符串中后拖的空格feval求由字符串給定的函數(shù)值findstr從一個字符串內(nèi)找出字符串isletter字母存在時返回真值isspace空格字符存在時返回真值isstr輸入是一個字符串,返回真值lasterr返回上一個所產(chǎn)生MA