结构体在matlab中的应用.pdf
文本预览下载声明
(struct)
MALTABstructMATLABstruct C
4. 3.1
MATLABstruct
1.
structx
x.real = 0; % real0
x.imag = 0 % ximag0
x =
real: 0
imag: 0
x(2).real = 0; % x1×2
x(2).imag = 0;
scale
x(1).scale = 0;
xscalex(1)scale
x(1) %
ans =
real: 0
imag: 0
scale: 0
x(2) %
ans =
real: 0
imag: 0
scale: []
x realimagscale
clear x; x.real = [1 2 3 4 5]; x.imag = ones(10,10);
x(2).real = 123;
x(2).imag = rand(5,1);
x(3).real = x(1); x(3).imag = 3; x(3)
ans =
real: [1x1 struct]
imag: 3
4.3.1-1
1
green_house.name = ; %
green_house.volume = 2000; %
green_house.parameter.temperature = [31.2 30.4 31.6 28.7 %
29.7 31.1 30.9 29.6];
green_house.parameter.humidity = [62.1 59.5 57.7 61.5; %
62.0 61.9 59.2 57.5];
2
green_house %
green_house =
name:
volume: 2000
parameter: [1x1 struct]
green_house.parameter % . parameter
ans =
temperature: [2x4 double]
humidity: [2x4 double]
green_house.parameter.temperature % temperature
ans =
31.2000 30.4000 31.6000 28.7000
29.7000 31.1000 30.9000 29.6000
4.3.1-2
green_house(2,3).name = ; %2×3
green_house %
green_house =
2x3 struct array with fields:
name
volume
parameter
green_house(2,3) %
ans =
name:
volume: []
parameter: []
2. struct
struct
struct
s = sturct(field1,values1,field2,values2,…);
values1 valuese2
structvalues1 values2
values field
valuesx
1×1
s = struct(type,{big,little},color,{blue,red},x,{3,4})
s =
1x2 struct array with fields:
type
color
x
1×2 stype colorx3struct{big,little}{blue,red}{3,4}1×2
s(1,1)
ans =
type: big
color: blue
x: 3
s(1,2)
ans =
type: little
color: red
x: 4
struct
s = struct(type,{big;little},color,{blue;red},x,{3;4})
s =
2x1 struct array with fields:
type
color
x
2×1
struct
4.3.1-3 struct
1 struct
a = cell(2,3); % 2×3
green_house_1=struct(name,a,volume,a,parameter,a(1,2))
green_house_1 =
2x3 struct array with fields:
name
volume
parameter
2 struct
green_house_2=struct(
显示全部