www.gusucode.com > ecoder 案例源码程序 matlab代码 > ecoder/ImportParametersIntoSimulinkCodeDemoExample.m

    %% Import Externally Defined Parameters into Simulink
% This model shows how to generate code that accesses the fields of a data structure.
% The data structure is defined in hand-written (legacy) code and accessed via pointer.
% 
% This technique enables users to switch between complete sets of parameters at run-time
% (e.g., reference & working versions).
%% Open Example Model
% Open the example model |rtwdemo_importstruct|.

% Copyright 2015 The MathWorks, Inc.

open_system('rtwdemo_importstruct')
%% Instructions
% # Inspect the handwritten user C-files containing the struct by double-clicking "View User C-files" in the model.
%     Look at the header file |rtwdemo_importstruct_user.h| and the source file |rtwdemo_importstruct_user.c|. 
% # Look at the *Custom Code* configuration by double-clicking the corresponding button in the model.
%     Inspect the *Initialize function* of the *Include custom c-code in generated* section to see how to add
%     custom initialization function calls to the generated code. To see how to include custom C-files, look at
%     *Source files* in the *Include list of additional* section.
% # View the custom storage class of the |ECoderDemos| package used in the model by double-clicking
%      "Custom Storage Class Definition" in the model, and then selecting |StructPointer|. Inspect the settings
%      of the tabs *General* and *Structure Attributes*. Change the attributes and watch the changes in the
%      preview window. Note that you can specify the pointer name within the data object itself by setting the
%      struct name to |Instance specific|.
% # Open the MATLAB program used to generate the data objects by double-clicking "View MATLAB code for Generating
%     Variables" in the model. This file is executed by referencing it in the *PostLoadFcn* Callback of the
%     Model Properties dialog box.
% # Look at the workspace variables by clicking the "View Workspace Variables" button in the model.
% # Generate code for the model by double-clicking "Generate Code." The code
%      generation report appears. Open the model C-file |rtwdemo_importstruct.c|. Inspect the model step
%      function |rtwdemo_importstruct_step|. Notice the user-specific code in the model initialization function 
%     |rtwdemo_importstruct_initialize|.