matlab教程第三章字符串、元胞和构架数组(编辑修改稿)内容摘要:

[1x1 sym] [+ ] [3x3 double] [] 8 元胞数组内容的调取 【例 】元胞数组内容的调取示例。 ( 1) f1=R_A_C(1,3) class(f1) f1 = [1x1 sym] ans = cell ( 2) f2=R_A_C{1,3} class(f2) f2 = sin(3*t)*exp(t) ans = sym ( 3) f3=R_A_C{1,1}(:,[1 2 5 6]) f3 = 这是 元胞创建 ( 4) [f4,f5,f6]=deal(R_A_C{[1,3,4]}) f4 = 这是 元胞数组创建算例 1 f5 = 10 9 8 7 6 5 4 3 2 1 f6 = 1 4 7 2 5 8 3 6 9 元胞数组转换函数 【例 】常用元胞数组转换函示例。 ( 1) num2cell 把数值数组转换成元胞数组 rand(39。 state39。 ,0)。 A=rand(2,3,2) C1=num2cell(A) A(:,:,1) = A(:,:,2) = C1(:,:,1) = [] [] [] [] [] [] C1(:,:,2) = [] [] [] 9 [] [] [] C2=num2cell(A,1) C2(:,:,1) = [2x1 double] [2x1 double] [2x1 double] C2(:,:,2) = [2x1 double] [2x1 double] [2x1 double] C3=num2cell(A,[2,3]) C3 = [1x3x2 double] [1x3x2 double] ( 2) clear,x=zeros(4,5)。 x(:)=1:20 C4=mat2cell(x, [2 2], [3 2]) celldisp(C4) x = 1 5 9 13 17 2 6 10 14 18 3 7 11 15 19 4 8 12 16 20 C4 = [2x3 double] [2x2 double] [2x3 double] [2x2 double] C4{1,1} = 1 5 9 2 6 10 C4{2,1} = 3 7 11 4 8 12 C4{1,2} = 13 17 14 18 C4{2,2} = 15 19 16 20 ( 3) D=cell2mat(C4(1,:)) D = 1 5 9 13 17 2 6 10 14 18 构架数组 构架数组的创建和显示 直接创建法及显示 【例 】本例通过温室数据(包括温室名、容积、温度、湿度等)演示:单构架的 10 创建和显示。 ( 1) =39。 一号房 39。 % 1 =39。 2020 立方米 39。 % 2 =[ ]。 %3 =[ ]。 %4 ( 2)显示“单构架”结构和内容 green_house % 5 green_house = name: 39。 一号房 39。 volume: 39。 2020 立方米 39。 parameter: [1x1 struct] % 6 ans = temperature: [2x4 double] humidity: [2x4 double] % 7 ans = 【例 】本例演示构架数组的创建和显示,并利用构架数组保存一个温室群的数据。 本例的运行以例。 ( 1) green_house(2,3).name=39。 六号房 39。 % 1 ( 2) green_house % 2 green_house = 2x3 struct array with fields: name volume parameter green_house(2,3) % 3 ans = name: 39。 六号房 39。 volume: [] parameter: [] 利用构造函数创建构架数组 【例 】利用构造函数 struct,建立温室群的数据库。 ( 1) a=cell(2,3)。 green_house_1=struct(39。 name39。 ,a,39。 volume39。 ,a,39。 parameter39。 ,a(1,2)) % 2 green_house_1 = 2x3 struct array with fields: name volume 11 parameter ( 2) green_house_2=struct(39。 name39。 ,a,39。 volume39。 ,[],39。 parameter39。 ,[]) % 3 green_house_2 = 2x3 struct array with fields: name volume parameter ( 3) green_hopuse_3(2,3)=struct(39。 name39。 ,[],39。 volume39。 ,[],39。 parameter39。 ,[])%4 green_hopuse_3 = 2x3 struct array with fields: name volume parameter (。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。