Data Logging With a File Scope

This example shows how to use an Simulink® Real-Time™ file scope to log signal data to the file system on the target computer. Signals are logged during model execution. At the end of the run, the data is read from the file, uploaded to the development computer and plotted.

Open, Build, and Download the Model

Open the model xpcFileLogging. This model generates 20 sinusoids, each having a different amplitude. The signals are logged to the file fLogData.dat in the file system root directory on the target computer.

Note: Scopes of type 'target' are limited to 10 signals. However, scopes of type 'host' and 'file' can store a number of signals limited only by the hardware resources of the target computer.

% Open the model.
mdlOpen = 0;
systems = find_system('type', 'block_diagram');
if all(~strcmp('xpcosc', systems))
  mdlOpen = 1;

Build the model and download to the target computer

set_param('xpcFileLogging','RTWVerbose','off'); % Configure for a non-Verbose build.
rtwbuild('xpcFileLogging');                     % Build and download application.

% Close the model if we opened it.
if (mdlOpen)
### Starting Simulink Real-Time build procedure for model: xpcFileLogging
### Generated code for 'xpcFileLogging' is up to date because no structural, parameter or code replacement library changes were found.
### Successful completion of build procedure for model: xpcFileLogging
### Looking for target: SGI7
### Download model onto target: SGI7

Run the Model

Using the Simulink Real-Time object variable, tg, start the model.

tg =;


% Capture the target computer screen which displays the sinusoids in two target scopes.

% Wait until the run is complete.
while strcmp(tg.Status, 'running')

Upload Data to the Development Computer and Plot.

% Attach to the target computer file system.

% Open the file, read the data, close the file.

% Unpack the data.

% Plot 1 second of the data.
figure; plot(,21),,1:20));
set(gca,'XLim',[0 1]); grid on;
xlabel('Time (sec)'); ylabel('Amplitude');

Was this topic helpful?