matlab中的结构体

今天用imfinfo函数

>> K = imfinfo(‘colorbar_copy1.jpg’)

K =

包含以下字段的 struct:

Filename: 'E:\matlab\colorbar_copy1.jpg'
FileModDate: '24-May-2018 07:09:11'
FileSize: 3019
Format: 'jpg'
FormatVersion: ''
Width: 400
Height: 300
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}

读取一个参数

>> ans(1).Width

ans =

400

所以在此总结下结构体:

扫描二维码关注公众号,回复: 1004830 查看本文章

1、直接创建结构体

>> stu(1).name='zhangsan';
>> stu(1).age=28;
>> stu(1).gender='male';
>> stu(2).name='lisi';
>> stu(2).age=29;
>> stu(2).gender='male';

2、使用struct函数也可以创建结构,该函数产生或把其他形式的数据转换为结构数组。

struct的使用格式为:

s = sturct('field1',values1,'field2',values2,…);

结构体处理的的一些函数 :

1.删除结构体操作rmfield()
s2=rmfield(s1,’color’)%删除s1中的一个字段color
s2=rmfield(s1,{‘color’,‘type’})%删除s1中的2个字段color和type

2.isstruct(s2)-判断是否为结构体

3.isfield(s2,’a’)-判断’a’字段是否属于这个结构体
  b=isfield(s,{‘type’,’color’})-同时判断两个字段是否属于结构体,返回值就是两个数。

4.fieldnames(s)-获取s结构体中的字段名字 

5.orderfields(s)-对s结构体中的字段进行排序,按首字母顺序

6.getfield()-取得结构体字段的值

7.setfield()-对结构体的字段赋予新的值

8.struct2cell(s)-将结构体s转换为单元数组

这里以以K为例来验证这些参数

 

猜你喜欢

转载自www.cnblogs.com/zhongguo135/p/9080931.html
今日推荐