matlab——第四章 字符串數(shù)組、元胞數(shù)組.ppt_第1頁
matlab——第四章 字符串數(shù)組、元胞數(shù)組.ppt_第2頁
matlab——第四章 字符串數(shù)組、元胞數(shù)組.ppt_第3頁
matlab——第四章 字符串數(shù)組、元胞數(shù)組.ppt_第4頁
matlab——第四章 字符串數(shù)組、元胞數(shù)組.ppt_第5頁
已閱讀5頁,還剩31頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

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=How about this character string? t = How about this character string? size(t) ans = 1 32 whos Name Size Bytes Class t 1x32 64 char array Grand total is 34 elements using 80 bytes, u=abs(t) u = Columns 1 through 12 72 1

2、11 119 32 97 98 111 117 116 32 116 104 Columns 13 through 24 105 115 32 99 104 97 114 97 99 116 101 114 Columns 25 through 32 32 115 116 114 105 110 103 63 char(u) ans = How about this character string?,u=t(16:24) u = character u= Hello, ; v= World! ;,v= Character strings having more than one row mu

3、st have the same number of column just like matrices! v = Character strings having more than one row must have the same number of column just like matrices!,w=u v w = Hello,World! disp(w) Hello,World!, lengends=char(Wilt,Russel,Kareem) lengends = Wilt Russel Kareem, char(one,tow,three) ans = one tow

4、 three strvcat(one,two,three) ans = one two three,4.1.2數(shù)字與字符串的相互轉(zhuǎn)換,rad=2.5; area=pi*rad2; t= A circle of radius num2str(rad) has an area of num2str(area) . ; disp(t) A circle of radius 2.5 has an area of 19.63,t=sprintf( A circle of radius %.4g has an area of %.4g. ,rad, area); disp(t) A circle of r

5、adius 2.5 has an area of 19.63. fprintf( A circle of radius %.4g has an area of %.4g.n ,rad, area) A circle of radius 2.5 has an area of 19.63.,4.1.3字符串函數(shù),a=eval( sqrt(2) ) a = 1.4142 eval( a=sqrt(2) ) a = 1.4142,a=feval( sqrt ,2) a = 1.4142,b=Peter Piper picked a peck of pickled peppers ; findstr(b

6、, ) % find space ans = 6 12 19 21 26 29 37 findstr(b, p ) % find the letter p ans = 9 13 22 30 38 40 41 find (b= = p ) % for single character searches ans = 9 13 22 30 38 40 41 findstr(b, cow ) % find the word cow ans = findstr(b, pick ) % find the string pick ans = 13 30, strrep(b, p , P ) % capita

7、lize all p s ans = Peter PiPer Picked a Peck of Pickled PePPers strrep(b, Peter , Pamela ) % change Peter to Pamela ans = Pamela Piper picked a peck of pickled peppers,disp(b) Peter Piper picked a peck of pickled peppers strtok(b) % ans = Peter c, r=strtok(b) c = Peter r = Piper picked a peck of pic

8、kled peppers strtok(b,a) ans = Peter Piper picked,4.2單元數(shù)組,4.2.1單元數(shù)組的創(chuàng)建, A(1,1)=1 2 3;4 5 6;7 8 9; A(1,2)=2+3i; A(2,1)=A character atring; A(2,2)=12:-2:0; A A = 3x3 double 2.0000+ 3.0000i A character atring 1x7 double, A1,1=1 2 3;4 5 6;7 8 9; A1,2=2+3i; A2,1=A character string; A2,2=12:-2:0; A A = 3x

9、3 double 2.0000+ 3.0000i A character string 1x7 double,單元索引,按值尋址, A(1,1) ans = 3x3 double, A1,1 ans = 1 2 3 4 5 6 7 8 9, celldisp(A) A1,1 = 1 2 3 4 5 6 7 8 9 A2,1 = A character atring A1,2 = 2.0000 + 3.0000i A2,2 = 12 10 8 6 4 2 0 cellplot(A,legend), B=1 2,John Smith,;2+3i,5 B = 1x2 double John Smit

10、h 2.0000+ 3.0000i 5, C=cell(2,3) C = , C(1,1)=This doesnt work ? Conversion to cell from char is not possible., C(1,1)=This does work C = This does work C2,3=This works too C = This does work This works too,4.2.2單元數(shù)組處理, A A = 3x3 double 2.0000+ 3.0000i A character string 1x7 double B B = 1x2 double

11、John Smith 2.0000+ 3.0000i 5 C=A;B C = 3x3 double 2.0000+ 3.0000i A character string 1x7 double 1x2 double John Smith 2.0000+ 3.0000i 5, D=C(1 3,:) D = 3x3 double 2.0000+ 3.0000i 1x2 double John Smith C(3,:)= C = 3x3 double 2.0000+ 3.0000i A character string 1x7 double 2.0000+ 3.0000i 5,4.2.3獲得單元數(shù)組的

12、內(nèi)容, B B = 1x2 double John Smith 2.0000+ 3.0000i 5 x=B2,2 x = 5 class(x) ans = double, y=B(2,2) y = 5 y=B(4) y = 5 class(y) ans = cell class(y1) ans = double, d,e=deal(B:,2) d = John Smith e = 5, B:,2 ans = John Smith ans = 5 d=B:,2 ? Illegal right hand side in assignment. Too many elements., celldis

13、p(A) A1,1 = 1 2 3 4 5 6 7 8 9 A2,1 = A character string A1,2 = 2.0000 + 3.0000i A2,2 = 12 10 8 6 4 2 0, A1,1(3,:) ans = 7 8 9 A4(2:5) ans = 10 8 6 4 A2,1(3:11) ans = character,4.3結(jié)構(gòu)數(shù)組,4.3.1創(chuàng)建結(jié)構(gòu)數(shù)組, circle.radius=2.5; circle.center=0,1; circle.linestyle=-; circle.color=red; circle circle = radius: 2.5

14、000 center: 0 1 linestyle: - color: red, circle(2).radius=3.4; circle(2).color=green; circle(2).linestyle=:; circle(2).center=2.3 -1.2; circle circle = 1x2 struct array with fields: radius center linestyle color, circle(2).radius=sqrt(2); circle circle = 1x2 struct array with fields: radius center l

15、inestyle color circle.radius ans = 2.5000 ans = sqrt(2), Cradius=2.5 3.4; Ccenter=0 1;2.3 -1.2; Clinestyle=- :; Ccolor=red,green;, circle(3).radius=25.4; circle(3).center= -1 0; circle(3).linestyle=-.; circle(3).color=blue;, Cradius(3)=25.4; Ccenter(3,:)=-1 0; Clinestyle3=-.; Ccolor3=blue,myfunc(cir

16、cle) myfunc(Cradius,Ccenter,Clinestyle,Ccolor), circle(1).filled=yes circle = 1x3 struct array with fields: radius center linestyle color filled circle.filled ans = yes ans = ans = , circle(2).filled=no; circle(3).filled=yes; circle.filled ans = yes ans = no ans = ye, values1=2.5 sqrt(2),25.4; value

17、s2=0 1 2.3 -1.2 -1 0; values3=-,:,-.; values4=red,green,blue; values5=yes,no,yes; CIRCLE=struct(radius,values1,center,values2,.) linestyle,values3,color,values4,filled,values5) CIRCLE = 1x3 struct array with fields: radius center linestyle color filled,4.3.2結(jié)構(gòu)處理, A=circle CIRCLE A = 1x6 struct array

18、 with fields: radius center linestyle color filled, square.width=5; square.height=14; square.center=zeros(1,2); square.rotation=pi/4; B=circle square ? Error using = horzcat CAT arguments are not consistent in structure field number.,4.3.3獲取結(jié)構(gòu)內(nèi)容,circle circle = 1x3 struct array with fields: radius c

19、enter linestyle color filled rad2=circle(2).radius rad2 = sqrt(2) circle(1).radius ans = 2.5000, col=circle.color ? Illegal right hand side in assignment. Too many elements.,c1,c2,c3=deal(circle.color) c1 = red c2 = green c3 = blue,4.3.4結(jié)構(gòu)函數(shù),circle = 1x3 struct array with fields: radius center linestyle color filled, fieldnames(circle) ans = radius center linestyle color filled, isfield(circle,color) a

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論