当前位置:网站首页>Matlab struct function (structure array)
Matlab struct function (structure array)
2022-07-05 11:58:00 【**inevitable**】
List of articles
grammar
s = struct
s = struct(field,value)
s = struct(field1,value1,...,fieldN,valueN)
s = struct([])
s = struct(obj)
explain
s = struct % Create a scalar without any fields (1×1) Structure .
s = struct(field,value)
% Create an array of structures with specified fields and values .
%value The input parameter can be any data type , For example, numerical value 、 Boolean value 、 Character or cell array
% If value Not a cellular array , perhaps value Is a scalar cell array , be s Is a scalar structure
% for example ,s = struct('a',[1 2 3]) Create a 1×1 Structure , among s.a = [1 2 3]
% If value Is a non scalar cell array , be s Is the dimension and value The same structure array .s Each element of contains value The corresponding element of
% for example ,s = struct('x',{'a','b'},'y','c') return s(1).x = 'a'、s(2).x = 'b'、s(1).y = 'c' and s(2).y = 'c'
% If value Is an empty cell array {}, be s It's empty (0×0) Structure
s = struct(field1,value1,...,fieldN,valueN) Create multiple fields
% aggregate value1,...,valueN Any non scalar cell array in must have the same dimension
% If value All inputs of are not cell arrays , perhaps value All inputs as cell arrays in are scalars , be s Is a scalar structure
% If all value All inputs are non scalar cell arrays , be s Has the same dimension as a non scalar cell array
% For any array whose type is scalar cell array or any other data type value,struct take value Insert the content of s In the relevant fields of all elements of
% If anything value The input is an empty cell array {}, The output s It's empty (0×0) Structure
% To specify an empty field and keep the values of other fields , Please switch to [] As value Input
s = struct([]) Create an empty without any fields (0×0) Structure
s = struct(obj) Create include and obj The scalar structure of the field name and value corresponding to the attribute of
%struct Functions do not convert obj, It's going to be s Create a new structure . This structure does not retain class information , So dedicated 、 Protected and hidden properties in s Become a public field
%struct Function will warn you when you use this syntax
Input parameters
filed : Field name
Field name , Specify as character vector or string scalar . Valid field names begin with a letter , It can contain letters 、 Numbers and underscores . The maximum length of a field name is namelengthmax Value returned by function
value: value
value , Specify as an array of any type . If value Any input is a non scalar cell array , Then all non scalar cell array inputs must have the same dimension . If value Any input is an empty cell array {}, The output is an empty structure array . To specify a single empty field , Please use [].
obj: object
object , Specify as a scalar or an array of objects .struct Function will obj The attribute of is copied into the field of the new scalar structure .struct Functions cannot create structures based on most basic data types . for example , If obj have double or char data type , be struct An error message will be sent . however ,struct The attributes of the table or schedule will be returned as a structure .
Example
example 1: Store relevant data variables in the structure
% Create a structure by adding fields using dot notation
data.x = linspace(0,2*pi);
data.y = sin(data.x);
data.title = 'y = sin(x)'
The results are shown below :
% Draw sine wave , Here, reference by field name x and y Array of values , Then add the title
plot(data.x,data.y)
title(data.title)
The results are shown below :
example 2: A structure with one field
% Create a non scalar structure containing a field
field = 'f';
value = {'some text';
[10, 20, 30];
magic(5)};
s = struct(field,value)
% View the content of each element
s.f
The results are shown below :
% Accessing fields of non scalar structures ( for example s.f) when ,MATLAB Return a comma separated list
% In this example ,s.f Equivalent to s(1).f, s(2).f, s(3).f

example 3: A structure with multiple fields
field1 = 'f1'; value1 = zeros(1,10);
field2 = 'f2'; value2 = {'a', 'b'};
field3 = 'f3'; value3 = {pi, pi.^2};
field4 = 'f4'; value4 = {'fourth'};
s = struct(field1,value1,field2,value2,field3,value3,field4,value4)
%value2 and value3 The cell array of is 1×2 Array , therefore s It's also 1×2 Array
% because value1 It's a numerical array, not a cellular array , therefore s(1).f1 and s(2).f1 Have the same content
% Similarly , because value4 The cell array of has a single element , therefore s(1).f4 and s(2).f4 Have the same content
The results are shown below :
example 4: Structure with empty fields
% Create a structure containing an empty field . Use [] Specify the value of the empty field
s = struct('f1','a','f2',[])
The results are shown below :
example 5: Fields containing cell arrays
field = 'mycell';
value = {
{'a','b','c'}};
s = struct(field,value)
The results are shown below :
example 6: Empty structure
% Create an empty structure with multiple fields
s = struct('a',{},'b',{},'c',{})
The results are shown below :
example 7: Nested structure
% Create a nested structure , among a Is a structure with a field , This field contains another structure
a.b = struct('c',{},'d',{})
% see a.b The name of the field
fieldnames(a.b)
The results are shown below :
边栏推荐
- Hiengine: comparable to the local cloud native memory database engine
- codeforces每日5题(均1700)-第五天
- 16 channel water lamp experiment based on Proteus (assembly language)
- 1 plug-in to handle advertisements in web pages
- iTOP-3568开发板NPU使用安装RKNN Toolkit Lite2
- 【使用TensorRT通过ONNX部署Pytorch项目】
- 多表操作-子查询
- Check the debug port information in rancher and do idea remote JVM debug
- splunk配置163邮箱告警
- pytorch-多层感知机MLP
猜你喜欢

Linux Installation and deployment lamp (apache+mysql+php)

Redis集群的重定向

Simply solve the problem that the node in the redis cluster cannot read data (error) moved

如何让你的产品越贵越好卖
![[upsampling method opencv interpolation]](/img/6b/5e8f3c2844f0cbbbf03022e0efd5f0.png)
[upsampling method opencv interpolation]

Pytorch softmax regression

13.(地图数据篇)百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换

Redis master-slave mode
![[pytorch pre training model modification, addition and deletion of specific layers]](/img/cb/aa0b1116ec9b98e3ee5725aa58f4fe.png)
[pytorch pre training model modification, addition and deletion of specific layers]

mmclassification 训练自定义数据
随机推荐
pytorch-多层感知机MLP
Redirection of redis cluster
Linux安装部署LAMP(Apache+MySQL+PHP)
【pytorch 修改预训练模型:实测加载预训练模型与模型随机初始化差别不大】
Solve readobjectstart: expect {or N, but found n, error found in 1 byte of
[loss functions of L1, L2 and smooth L1]
Mmclassification training custom data
[mainstream nivida graphics card deep learning / reinforcement learning /ai computing power summary]
1 plug-in to handle advertisements in web pages
1个插件搞定网页中的广告
无线WIFI学习型8路发射遥控模块
How to clear floating?
[singleshotmultiboxdetector (SSD, single step multi frame target detection)]
Shell script file traversal STR to array string splicing
Principle of redis cluster mode
【TFLite, ONNX, CoreML, TensorRT Export】
Troubleshooting of high memory usage of redis in a production environment
Programmers are involved and maintain industry competitiveness
Implementation of array hash function in PHP
abap查表程序