This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Data Logging With Simulation Data Inspector (SDI)

This example shows how to use Simulink® Real-Time™ with an SDI log of signal data. Signals are logged during model execution. At the end of the run, the SDI interface displays the signal. This example show how to get the signals from SDI interface by using the command line.

Open, Build, and Download the Model

Open the model xpcFileLogging. This model generates 20 sinusoids, each having a different amplitude.

Note: Scopes of type 'target' are limited to 10 signals.

Open the model.

mdlOpen = 0;
systems = find_system('type', 'block_diagram');
if all(~strcmp('xpcosc', systems))
    mdlOpen = 1;
    open_system(fullfile(matlabroot,'toolbox','rtw','targets','xpc','xpcdemos','xpcFileLogging'));
end

Build the model and download to the target computer

  • Configure for a non-Verbose build.

  • Build and download application.

set_param('xpcFileLogging','RTWVerbose','off');
rtwbuild('xpcFileLogging');
### 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
### Created MLDATX ..\xpcFileLogging.mldatx
### Looking for target: TargetPC1
### Download model onto target: TargetPC1
  • Close the model if we opened it.

if (mdlOpen)
    bdclose('xpcFileLogging');
end

Run the Model

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

tg = SimulinkRealTime.target;
start(tg);
pause(5);

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

tg.viewTargetScreen();

Wait until the run is complete.

while strcmp(tg.Status, 'running')
    pause(0.05);
end

Display the signals in the Simulation Data Inspector

To view the plotted signal data, open the Simulation Data Inspector.

Simulink.sdi.view

Retrieve and plot signal data from the Simulation Data Inspector

You can also retrieve the signal data from the SDI and plot the data by using these commands.

  • Get all the runs

  • Get the run information

runIds = Simulink.sdi.getAllRunIDs();
run = Simulink.sdi.getRun(runIds(end));
signals=run.SignalCount;
array=1;
  • Get the signal.

  • Get the signal objects.

  • Take only Sine values.

for signalIndex=1:signals
    signalID = run.getSignalIDByIndex(signalIndex);
    signalObj = Simulink.sdi.getSignal(signalID);
    if(~isempty(strfind(signalObj.Name,'Sine')))
        signalArray(:,array)=signalObj.Values(:,1).Data;
        timeValues=signalObj.Values(:,1).Time;
        array=array+1;
    end
end
  • Plot the signals.

plot(timeValues,signalArray);
grid on;
xlabel('Time (sec)'); ylabel('Amplitude');

More Information