資源描述:
《matlab——第四章字符串數(shù)組、元胞數(shù)組》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在教育資源-天天文庫。
1、第4章字符串數(shù)組、元胞數(shù)組和結(jié)構(gòu)數(shù)組4.1字符串數(shù)組4.2元胞數(shù)組(單元數(shù)組)4.3結(jié)構(gòu)數(shù)組(構(gòu)架數(shù)組)4.1字符串數(shù)組4.1.1字符串構(gòu)造>>t='Howaboutthischaracterstring?'t=Howaboutthischaracterstring?>>size(t)ans=132>>whosNameSizeBytesClasst1x3264chararrayGrandtotalis34elementsusing80bytes>>u=abs(t)u=Columns1through127211111932979811111711632116104Columns13through
2、241051153299104971149799116101114Columns25through323211511611410511010363>>char(u)ans=Howaboutthischaracterstring?>>u=t(16:24)u=character>>u=‘Hello,';>>v=‘World!';>>v=['Characterstringshavingmorethan''onerowmusthavethesamenumber''ofcolumnjustlikematrices!']v=Characterstringshavingmorethanonerowmusth
3、avethesamenumberofcolumnjustlikematrices!>>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=onetwothree4.1.2數(shù)字與字符串的相互轉(zhuǎn)換Dec2hex十進制數(shù)到十六進制字符串轉(zhuǎn)換fprintf把格式化的文本寫到文件中或顯
4、示屏上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(rad)…'hasanareaof’num2str(area)'.'];>>disp(t)Acirc
5、leofradius2.5hasanareaof19.63>>t=sprintf('Acircleofradius%.4ghasanareaof%.4g.’…,rad,area);>>disp(t)Acircleofradius2.5hasanareaof19.63.>>fprintf('Acircleofradius%.4ghasanareaof%.4g.‘…,rad,area)Acircleofradius2.5hasanareaof19.63.fprintf('%.0e',pi)3e+00fprintf('%.3e',pi)3.142e+00fprintf('%.10e'
6、,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.141592654fprintf('%.8.0g',pi)3fprintf('%.8.3g',pi)3.14fprintf('%.8.10g',pi)3.1415926544.1.3字符串函數(shù)eval(string)作為一個MATLAB命令求字符串的值b
7、lanks(n)返回一個n個零或空格的字符串deblank去掉字符串中后拖的空格feval求由字符串給定的函數(shù)值findstr從一個字符串內(nèi)找出字符串isletter字母存在時返回真值isspace空格字符存在時返回真值isstr輸入是一個字符串,返回真值lasterr返回上一個所產(chǎn)生MATLAB錯誤的字符串strcmp字符串相同,返回真值strrep用一個字符串替換另一個字符串strtok在一個