![47d1d1dcb284c9a2f8aa36c7bf177210.png](https://i-blog.csdnimg.cn/blog_migrate/0771e788c621776cbf646baad008ecb9.jpeg)
Temporary Data: Base Workspace临时数据:基本工作区
Use the base workspace to temporarily store data:
使用基本工作区临时存储数据:
• While you learn to use Simulink
当你学习使用Simulink时
• When you need to quickly create variables while experimenting with modeling techniques
当您需要在试验建模技术时快速创建变量时
• When you do not need to store the data permanently
当您不需要永久存储数据时
To create variables in the base workspace, you can use the MATLAB command prompt or the Model Explorer. All open models can use the data that you create in the base workspace.
要在基本工作区中创建变量,您可以使用MATLAB命令提示符或模型资源管理器。所有打开的模型都可以使用您在基本工作区中创建的数据。
If you use variables to specify numeric block parameters in the model, you can programmatically change the parameter values during simulation by using commands at the command prompt. To programmatically change the values of parameters that you store in the model workspace or data dictionaries, you must use the function interfaces for those storage locations.
如果使用变量在模型中指定数值块参数,则可以通过在命令提示符下使用命令在模拟期间以编程方式更改参数值。若要以编程方式更改存储在模型工作区或数据字典中的参数值,必须使用这些存储位置的函数接口。
To permanently store base workspace data before you end a MATLAB session, you can save the data in a MAT-file or a script file. During a later session, you can load the data from the file. However, if you make changes to the data in the base workspace, you must save the data to the file again.
要在MATLAB会话结束之前永久存储基本工作区数据,可以将数据保存在MAT-file或脚本文件中。在以后的会话中,可以从文件中加载数据。但是,如果对基工作区中的数据进行更改,则必须再次将数据保存到文件中。
Consider instead using a model workspace or data dictionary to permanently store data.
请考虑使用模型工作区或数据字典来永久存储数据。Local Data: Model Workspace本地数据:模型工作区
Use a model workspace to store data that you use only in the associated model. This data can include:
使用模型工作区存储只在关联模型中使用的数据。这些数据可以包括:
• Constant parameters, for example, numeric variables that you use to specify block parameter values.
常量参数,例如,用于指定块参数值的数值变量。
• Data objects, such as Simulink.Signal and Simulink.Parameter objects, that you use to control signal and parameter characteristics. However, signal objects in a model workspace can use only the Auto storage class. If you store an AUTOSAR.Parameter object in a model workspace, the code generator ignores the storage class that you specify for the object.
数据对象,例如Simulink。信号和Simulink。参数对象,用于控制信号和参数特征。但是,模型工作区中的信号对象只能使用Autostorage类。如果在模型工作区中存储AUTOSAR.Parameter对象,则代码生成器将忽略为该对象指定的存储类。
• Simulink.NumericType objects that you use to specify data types. However, you cannot use the object as a data type alias. You must set the IsAlias property to false.
Simulink.用于指定数据类型的NumericType对象。但是,不能将该对象用作数据类型别名。必须将IsAlias属性设置为false。
• Model arguments.
模型参数。
You can improve model portability and establish data ownership by storing the data in the model workspace. In this case, the model file permanently stores the data.
您可以通过在模型工作区中存储数据来提高模型的可移植性并建立数据所有权。在这种情况下,模型文件将永久存储数据。
In a model reference hierarchy, each model workspace acts as a unique namespace. Therefore, you can use the same variable name in multiple model workspaces. You can then assign a unique variable value for each model.
在模型引用层次结构中,每个模型工作区充当一个唯一的名称空间。因此,可以在多个模型工作区中使用相同的变量名。然后可以为每个模型分配一个唯一的变量值。
You can use the Model Explorer to manipulate model workspace data. Alternatively, you can use the command prompt or scripts in conjunction with the model workspace programmatic interface.
您可以使用模型资源管理器来操作模型工作区数据。或者,您可以将命令提示符或脚本与模型工作区编程接口一起使用。
For more information about using model workspaces to store local data, see “Model Workspaces” on page 67-119.
有关使用模型工作区存储本地数据的详细信息,请参阅第67-119页上的“模型工作区”。
Global and Shared Data: Data Dictionary
全球和共享数据:数据字典
A data dictionary is a standalone file that permanently stores data. Use data dictionaries instead of the base workspace to partition data, track changes, control access, and share data. If you link a model to a data dictionary, you can still use variables in the base workspace by configuring access from either the model or the dictionary.
数据字典是一个永久存储数据的独立文件。使用数据字典而不是基本工作区来分区数据、跟踪更改、控制访问和共享数据。如果将模型链接到数据字典,您仍然可以通过配置来自模型或字典的访问来在基本工作区中使用变量。
As you can with model workspaces, you can use data dictionaries to directly associate data with a model. You can use this association to scope the data and to establish ownership.
与使用模型工作区一样,您可以使用数据字典直接将数据与模型关联。您可以使用此关联来确定数据的范围和建立所有权。
When you use dictionaries, you can partition the data by storing it in additional referenced dictionaries. However, each entry in a dictionary must use a unique name. You must manage each dictionary as a separate file.
使用字典时,可以通过将数据存储在其他引用的字典中来对数据进行分区。但是,字典中的每个条目都必须使用唯一的名称。您必须将每个字典作为单独的文件来管理。
Use a data dictionary to store data that multiple models or system components share. This data can include:
使用数据字典存储多个模型或系统组件共享的数据。这些数据可以包括:
• Numeric variables that multiple models use to specify block parameter values.
多个模型用于指定块参数值的数值变量。
• Simulink.AliasType and Simulink.NumericType objects that you use to specify data types in multiple models at once.
Simulink.AliasType和Simulink.NumericType对象,用于同时在多个模型中指定数据类型。
• Data objects, including signal objects (such as Simulink.Signal) that use a storage class other than Auto. If you have a Simulink Coder license, these objects can represent signals and tunable parameters that appear as global variables in the generated code.
数据对象,包括信号对象(例如Simulink)。信号),使用自动以外的存储类。如果您有一个SimulinkCoder许可证,那么这些对象可以表示作为全局变量出现在生成代码中的信号和可调参数。
• Simulink.Bus objects that you use to define signal interfaces between referenced models.
用于定义引用模型之间的信号接口的Simulink.总线对象。
• Simulink.ConfigSet objects that you use to maintain configuration parameter uniformity across multiple models.
用于在多个模型之间维护配置参数一致性的Simulink.ConfigSet对象。
• Enumerated type definitions, which you store using
使用枚举类型定义存储的
Simulink.data.dictionary.EnumTypeDefinition objects.
Enumtypedefinition对象。
You can use the Model Explorer to manipulate dictionary data. Alternatively, you can use the command prompt or scripts in conjunction with the data dictionary programmatic interface.
您可以使用模型资源管理器来操作字典数据。或者,您可以将命令提示符或脚本与数据字典编程接口一起使用。
For basic information about data dictionaries, see “What Is a Data Dictionary?” on page 71-2.
有关数据字典的基本信息,请参阅第71-2页的“什么是数据字典?”。