无法理解 Octave 结构声明
Fail to understand Octave structure declaration
Octave 中有一个新功能 - 结构。我从 Octave Structure.
那里得到了关于 Structure 的信息
我也得到了一些代码来创建这样的结构
data = struct;
data.timestep.sensor = struct;
但我在 Octave Structure 中从未收到过此类声明。所以我对这两条编码线感到困惑。
谁能帮我理解这两行?
首先,结构在 Octave 中并不是那么新(链接的文档页面已经可用于带有 last modified date March 2016 的 Octave 4.0.0)。
您刚刚尝试过创建结构吗?第一行只会生成一些空结构。
data = struct
data =
scalar structure containing the fields:
如您所见,还没有字段。
第二行(隐式)
- 将字段
timestep
添加到结构 data
,
- 将字段
sensor
添加到 timestep
,(隐含地)使 timestep
成为(子)结构,
- 使字段
sensor
本身成为一个空结构。
如果您之前的工作区中没有 data
变量(或已经有适当的结构),则第二行就足够了。然后,data
也被隐式生成为一个结构。
clear data;
data.timestep.sensor = struct
data =
scalar structure containing the fields:
timestep =
scalar structure containing the fields:
sensor =
scalar structure containing the fields:
如果已经有一个 data
变量,例如对于一些标量,这是行不通的,您需要两条线。
data = 42;
data.timestep.sensor = struct
error: scalar cannot be indexed with .
data = struct
data =
scalar structure containing the fields:
data.timestep.sensor = struct
data =
scalar structure containing the fields:
timestep =
scalar structure containing the fields:
sensor =
scalar structure containing the fields:
例如,您也可以使用 clear data
而不是 data = struct
。
希望对您有所帮助!如果不是,请在您的问题中提供更多详细信息,究竟是什么让您感到困惑。
Octave 中有一个新功能 - 结构。我从 Octave Structure.
那里得到了关于 Structure 的信息我也得到了一些代码来创建这样的结构
data = struct;
data.timestep.sensor = struct;
但我在 Octave Structure 中从未收到过此类声明。所以我对这两条编码线感到困惑。
谁能帮我理解这两行?
首先,结构在 Octave 中并不是那么新(链接的文档页面已经可用于带有 last modified date March 2016 的 Octave 4.0.0)。
您刚刚尝试过创建结构吗?第一行只会生成一些空结构。
data = struct
data =
scalar structure containing the fields:
如您所见,还没有字段。
第二行(隐式)
- 将字段
timestep
添加到结构data
, - 将字段
sensor
添加到timestep
,(隐含地)使timestep
成为(子)结构, - 使字段
sensor
本身成为一个空结构。
如果您之前的工作区中没有 data
变量(或已经有适当的结构),则第二行就足够了。然后,data
也被隐式生成为一个结构。
clear data;
data.timestep.sensor = struct
data =
scalar structure containing the fields:
timestep =
scalar structure containing the fields:
sensor =
scalar structure containing the fields:
如果已经有一个 data
变量,例如对于一些标量,这是行不通的,您需要两条线。
data = 42;
data.timestep.sensor = struct
error: scalar cannot be indexed with .
data = struct
data =
scalar structure containing the fields:
data.timestep.sensor = struct
data =
scalar structure containing the fields:
timestep =
scalar structure containing the fields:
sensor =
scalar structure containing the fields:
例如,您也可以使用 clear data
而不是 data = struct
。
希望对您有所帮助!如果不是,请在您的问题中提供更多详细信息,究竟是什么让您感到困惑。