Matlab 在生成的代码中使用Simulink参数
我使用m文件在MATLAB工作空间中初始化参数 这是文件的示例:Matlab 在生成的代码中使用Simulink参数,matlab,parameters,simulink,Matlab,Parameters,Simulink,我使用m文件在MATLAB工作空间中初始化参数 这是文件的示例: Pconstant=Simulink.Parameter; Pconstant.Value=3; Pconstant.CoderInfo.StorageClass = 'exportedGlobal'; Pgain=Simulink.Parameter; Pgain.Value=10; Pgain.CoderInfo.StorageClass = 'exportedGlobal'; 这些参数用作“增益”和“恒定”块中的值。我为
Pconstant=Simulink.Parameter;
Pconstant.Value=3;
Pconstant.CoderInfo.StorageClass = 'exportedGlobal';
Pgain=Simulink.Parameter;
Pgain.Value=10;
Pgain.CoderInfo.StorageClass = 'exportedGlobal';
这些参数用作“增益”和“恒定”块中的值。我为该模型生成c源代码,并在model_data.c文件中收到以下结构:
/* Block parameters (auto storage) */
P_ParameterTest_T ParameterTest_P = {
10.0, /* Expression: Pgain
* Referenced by: '<Root>/Gain'
*/
3.0, /* Expression: Pconstant
* Referenced by: '<Root>/Constant'
*/
};
但是这个解决方案对我不好。因为我不知道这些参数在哪里使用,也不知道结构的字段名
我是否可以编写代码,在使用Pconstant参数的所有结构字段中设置值?大概是这样的:
Pconstant = 1; //instead of parameters->Constant_Value = 1;
谢谢您的帮助。您说您已将存储类定义为
ExportedGlobal
,但在生成的代码中,它显示为“自动存储”,因此有些地方不太正确
要实现您想要的功能,我认为您需要在优化窗格中打开“内联参数”(请参阅),然后单击“配置…”按钮来定义您不希望内联的参数,即Pconstant
和Pgain
(请参阅文档中关于的位)。代码中的结构构造通常在关闭“内联参数”时使用
我猜您有Simulink编码器,所以您还应该在Simulink编码器文档中查看它如何在不同条件下为参数生成代码。从内存来看,它通常非常彻底。您说您已经将存储类定义为
ExportedGlobal
,但在生成的代码中,它显示为“自动存储”,因此有些地方不太正确
要实现您想要的功能,我认为您需要在优化窗格中打开“内联参数”(请参阅),然后单击“配置…”按钮来定义您不希望内联的参数,即Pconstant
和Pgain
(请参阅文档中关于的位)。代码中的结构构造通常在关闭“内联参数”时使用
我猜您有Simulink编码器,所以您还应该在Simulink编码器文档中查看它如何在不同条件下为参数生成代码。从记忆上看,这通常是相当彻底的。你说得对。当我打开“内联参数”时,一切正常。我可以使用
extern real\T Pconstant编码>并将所需值设置到参数中。非常感谢。你说得对。当我打开“内联参数”时,一切正常。我可以使用extern real\T Pconstant编码>并将所需值设置到参数中。非常感谢。
parameters = (BLOCK_PARAMETERS*)rtmGetDefaultParam(model);
parameters->Constant_Value = 1;
Pconstant = 1; //instead of parameters->Constant_Value = 1;