今天用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
所以在此總結下結構體:
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為例來驗證這些參數