%% Store Logged Signal Data During Simulation
% Simulate the sdoHydraulicCylinder model, and store the Pressures signal of the model.
% Log the Pressures signal that is output from the first port in the Cylinder Assembly block of the model.

Pressures = Simulink.SimulationData.SignalLoggingInfo;
Pressures.BlockPath = 'sdoHydraulicCylinder/Cylinder Assembly';
Pressures.OutputPortIndex = 1;

%
% Create a simulation scenario for the model, and specify the signal to log.

simulator = sdo.SimulationTest('sdoHydraulicCylinder');
simulator.LoggingInfo.Signals = [Pressures];

%
% Specify parameter values for simulation.

Ac = sdo.getParameterFromModel('sdoHydraulicCylinder','Ac');
Ac.Value = 0.5;
simulator.Parameters = Ac;

%
% Simulate the model.

sim_obj = sim(simulator);

%
% The specified signal Pressures is logged during simulation in the LoggedData property of sim_obj. After simulation, the sim command restores model parameter and model signal logging changes. If you want to preserve your changes, specify the RestoreSettingsAfterSim argument as false.

sim_obj = sim(simulator,'RestoreSettingsAfterSim',false);

% Copyright 2012 The MathWorks, Inc.