%% Save Simulation Data from Floating Scope
% This example shows how to save signals to the MATLAB(R) Workspace using a
% Floating Scope block.  You can follow the same
% procedure to save data from a Scope Viewer. To save data from a Scope or
% Time Scope block, see <docid:simulink_ug#bu55s2j-1>.
 
% Copyright 2019 The MathWorks, Inc.

%% 
% This example uses a modified version of the |vdp| model.  In this
% example, a floating scope is connected to the |x1| and |x2| signals. 
%% Set Up Signal Logging from the Floating Scope
%
model = 'vdpFloatingScope';
open_system(model);
%%
% # From the Floating Scope window, select *View* > *Configuration
% Properties*. 
% # On the *Logging* tab, select *Log/Unlog Viewer Signals to Workspace*.
% When you click this button, Simulink places logging symbols on the
% signals connected to the Floating Scope.
% # From the Simulink Editor, on the *Modeling* tab, click *Model Settings*.  
% # In the Configuration Properties window, select *Data
% Import/Export*.
% # Select the *Signal logging* check box. You can also set the parameter
% name from this window. The default parameter name is |logsout|.

%% Use Saved Simulation Data
% Run a simulation. Simulink saves data to the MATLAB Workspace in a
% variable |out|. 
out = sim(model);
%%
% Simulink saves all logged or saved simulation data as
% one structure. In |out|, the scope data object |logsout| has one element for
% each logged signal. 
%%
% In the MATLAB Command Window, plot the log data for |x1|.
x1_data = out.logsout.get('x1').Values.Data;
x1_time = out.logsout.get('x2').Values.Time;
plot(x1_time,x1_data);
