Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Windows Target   

Logging Signals to a Disk Drive

About Signal Logging

Logging signals to a disk drive is the process of saving (logging) data to a variable in your MATLAB workspace and then saving that data to a MAT-file on your disk drive. This allows you to use MATLAB functions for data analysis and MATLAB plotting functions for visualization.

Using the data archiving feature provided in the External Mode Control Panel, you can save data to a file during execution. Simulink external mode does not support data logging with Outport blocks in your Simulink model. This means you do not enter or select parameters on the Data I/O pane in the Configuration Parameters dialog box.

To use the data archiving feature with a Real-Time Windows Target application, you must add a Scope block to your Simulink model, and you must execute a real-time application.

Entering Scope Parameters

You save data to a disk drive by first saving the data to the MATLAB workspace through a Simulink Scope block. You need to set scope block parameters for data to be saved.

After you create a Simulink model and add a Scope block, you can enter the scope parameters for signal logging to a disk drive. This procedure uses the Simulink model rtwin_model.mdl as an example, and assumes you have already loaded that model.

  1. In the Simulink window, double-click the Scope block.

    A Scope window opens.

  2. On the toolbar, click the Parameters button.

    A Scope parameters dialog box opens.

  3. Click the Data history tab.

  4. Do one of the following:

    • If you are running a simulation, you can select the Limit data points to last check box, and enter the number of sample points to save.

    • If you are running an execution, do not select the Limit data points to last check box.

    The Limit data points to last check box is related to the Duration value in the External Signal & Triggering dialog box. The smaller of either value limits the number of sample points saved to the MATLAB workspace. When using Real-Time Windows Target software, we recommend that you use the Duration value to set the number of sample points you save. To set the Duration value, see Entering Signal and Triggering Properties.

  5. Select the Save data to workspace check box. In the Variable name text box, enter the name of a MATLAB variable. The default name is ScopeData.

    The Scope parameters dialog box is related to the Data Archiving dialog box. In the Scope parameters dialog box, you must select the Save data to workspace check box to be able to save data to a disk drive, for two reasons:

    • The data is first transferred from the data buffer to the MATLAB workspace before being written to a MAT-file.

    • The Variable name entered in the Scope parameters dialog box is the same as the one in the MATLAB workspace and the MAT-file.

    If you do not select the Save data to workspace check box, the MAT-files for data logging will be created, but they will be empty.

  6. From the Format list, choose eitherStructure with time, Structure, or Array(compatible with Version 2.0 through Version 2.2). For example, to save the sample times and signal values at those times, choose Structure with time. Your Data history pane looks similar to the next figure.

  7. Do one of the following:

    • Click Apply to apply the changes to your model and leave the dialog box open.

    • Click OK to apply the changes to your model and close the dialog box.

    You must rebuild your real-time application before connecting and starting the application with changed settings. If you do not rebuild after making changes, an error will occur.

Entering Signal and Triggering Properties

Data is saved to a disk drive by first saving the data to the MATLAB workspace through a Simulink Scope block. Signal and triggering properties need to be set when running a real-time application.

After you create a Simulink model and add a Scope block, you can enter the signal and triggering properties for data logging to a disk drive. This procedure uses the Simulink model rtwin_model.mdl as an example, and assumes you have already loaded that model:

  1. In the Simulink window, and from the Tools menu, click External Mode Control Panel.

    The External Mode Control Panel dialog box opens.

  2. Click the Signal & Triggering button.

    The External Signal & Triggering dialog box opens.

  3. Click the Select all button. From the Source list, choosemanual. From the Mode list, choose normal.

    The X under Signal selection designates that a signal has been tagged for data collection, and T designates that the signal has been tagged as a trigger signal.

  4. In the Duration field, enter the number of sample points in a data buffer. For example, if you have a sample rate of 1000 samples/second and a stop time of 10 seconds, then enter

    10000
    

    The Duration value is related to the Limit data points to last value in the Scope parameters dialog box. The smaller of either value limits the number of sample points saved to the MATLAB workspace. We recommend that you do not select the Limit data points to last check box, and use the Duration value to set the number of sample points saved.

    The Duration value specifies the number of contiguous points of data to be collected in each buffer of data. We recommend that you enter a Duration value equal to the total number of sample points you need to collect for a run. If you enter a value much less than the total number of sample points, you may lose logging sample points due to the time needed to transfer values from the data buffer to the MATLAB workspace.

    We also recommend setting the time axis for Simulink Scope blocks equal to the sample interval (in seconds) times the number of points in each data buffer. This setting will display one buffer of data across the entire Simulink Scope plot.

    The External Signal & Triggering dialog box looks similar to the next figure.

  5. Do one of the following:

    • Click Apply to apply the changes to your model and leave the dialog box open.

    • Click Close to apply the changes to your model and close the dialog box.

    You must click the Apply or Close button on the External Signal & Triggering dialog box for the changes you made to take effect, but you do not have to rebuild your real-time application.

Entering Data Archiving Parameters

The Data Archiving dialog box is related to the Scope parameters dialog box. In the Scope parameters dialog box, you must select the Save data to workspace check box to be able to save data to a disk drive, for two reasons:

If you do not select the Save data to workspace check box in the Scope parameters dialog box, the MAT-files for data logging will be created, but they will be empty.

After you create a Simulink model, you can enter the Data Archiving Parameters for data logging to a disk drive:

  1. In the Simulation window, and from the Tools menu, click External Mode Control Panel.

    The External Mode Control Panel dialog box opens:

  2. Click the Data Archiving button.

    The External Data Archiving dialog box opens. This dialog box allows you to specify data archiving options.

  3. Select the Enable archiving check box.

  4. In the Directory text box, enter the path to a directory on your disk drive. For example, if your MATLAB working directory is named mwd, enter

    c:\mwd
    
  5. In the File text box, enter the file name prefix for the data files to be saved. For example, enter

    data
    

    The MATLAB environment names the files data_0.mat, data_1.mat, etc. The number of files equals the total sample points. For example, if you set Duration to Total sample points, then only one file is created.

  6. Select the Append file suffix to variable names check box.

    Within each MAT-file, a variable is saved with the same name you entered in the Variable name text box (Data history pane on the Scope parameters dialog box). By selecting the Append file suffix to variable names check box, the same suffix that is added to the MAT-file is added to the variable name. For example, if you entered the variable name ScopeData, then within the file data_0.mat will be a variable ScopeData_0.

    Your External Data Archiving dialog box looks similar to the next figure.

  7. Click the Close button.

    The parameters you entered are applied to your model.

    There is no Apply button with this dialog box. You must click the Close button for the changes you make to take effect.

Plotting Logged Signal Data

You can use the MATLAB plotting functions for visualization of your non-real-time simulated data or your real-time executed data.

After running your real-time application and logging data to a disk drive, you can plot the data. This procedure uses the Simulink model rtwin_model.mdl as an example, and assumes you saved your data to the variable ScopeData:

  1. In the MATLAB Command Window, type

    ScopeData
    

    The MATLAB Command Window shows the structure of the variable ScopeData. The variable ScopeData is a MATLAB structure containing the fields time vector, signal structure, and a string containing the block name.

    ScopeData = 
             time: [10000x1 double]
          signals: [1x1 struct]
        blockName: 'rtwin_model/Scope'
    
  2. To list the MAT-files saved to your disk drive, type

    dir *.mat
    

    The MATLAB Command Window shows the MAT-files in your current working directory.

    ScopeData.mat
    
  3. To clear the MATLAB workspace and load the scope data, type

    clear 
    load ScopeData 
    who
    

    The MATLAB Command Window displays:

    Your variables are:
    ScopeData
    
  4. To plot the first 1000 points, type

    plot(ScopeData.time(1:1000), ScopeData_0.signals.values(1:1000))

    The MATLAB environment plots the first 1000 samples from 0.0000 to 0.9990 second.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS