www.gusucode.com > simulinkcoder 案例源码程序 matlab代码 > simulinkcoder/DefineDataIndependentlyDemoExample.m

    %% Define Data Independently from Model Diagram
% Simulink provides the capability to define data storage class as part of 
% the diagram. This approach is particularly useful for rapid prototyping 
% and hardware-in-the-loop testing.  
% 
% This model illustrates the functionality provided by
%
% * Inlining parameters
% * Signal storage reuse
% * Built-in data storage classes
%% Open Example Model
% Open the example model |rtwdemo_basicsc|.

% Copyright 2015 The MathWorks, Inc.

open_system('rtwdemo_basicsc')
%% Instructions
% Double-click the boxes in the model to configure data or generated code.
%
% To understand the configuration choices that are available in the model, read the descriptions
% below.
%% Tunable Parameters and Signal Storage Reuse Off
% If the default parameter behavior is tunable and signal storage reuse is
% off:
%
% Motivation:
%
% * Provide visibility (persistence) for all data
% * Useful for simulation and rapid prototyping
% 
% Behavior:
%
% * All parameters and signals are members of persistent data structures
% * All states and root-level I/O are members of persistent data structures 
% 
% Advantages:
%
% * Easy access to data via model-wide settings
% 
% Disadvantages:
%
% * Generated code is non-optimal
% * Minimal control over variable names
%% |Auto| Storage Class
% If the default parameter behavior is inlined and signal storage reuse is
% on:
%
% Motivation:
%
% * Maximize efficiency of the generated code
% 
% Behavior:
%
% * Parameters are inlined and intermediate signals are eliminated
% * All states and root-level I/O are members of persistent data structures
% 
% Advantages:
%
% * Optimized code generation
% * Default behavior when optimizations enabled (easy to use)
% 
% Disadvantages:
%
% * Parameters and signals do not appear as variables in the generated code 
%% |SimulinkGlobal| Storage Class
% If the default parameter behavior is inlined and signal storage reuse is
% on:
%
% Motivation:
%
% * Provide visibility (persistence) for selected data
% 
% Behavior:
%
% * Select parameters and signals are members of persistent data structures 
% * All states and root-level I/O are members of persistent data structures
% 
% Advantages:
%
% * Only increase memory usage for data of interest
% * Provides visibility to data without limitations
% 
% Disadvantages:
%
% * Minimal control over variable names
% 
% How to specify |SimulinkGlobal|:
%
% * Parameters: Tunable + |Auto| storage class
% * Signals: Test point + |Auto| storage class
% * States: |Auto| storage class
%% Unstructured Storage Class (e.g., |ExportedGlobal|)
% If the default parameter behavior is inlined and signal storage reuse is
% on:
%
% Motivation:
%
% * Interface to global data in hand-written (legacy) code
% 
% Behavior:
%
% * Select parameters and signals are global, unstructured variables
% * Select states and root-level I/O are global, unstructured variables 
% 
% Advantages:
%
% * Data names are preserved in the generated code
% 
% Disadvantages:
%
% * Imposes certain modeling restrictions
% * Disables certain code optimizations