Why Simulink "To Workspace" block doesn't create timeseries data?

14 views (last 30 days)
Saving data from the sensor to the workspace in external mode

Answers (1)

Amish
Amish on 15 Sep 2023
Hi Khalid,
As I understand, you are unable to create timeseries data using the “to workspace” Simulink block while saving data from the sensor in the External mode. The reason for this is that the Simulink "To Workspace" block is made to capture simulation data and export it to the MATLAB workspace. By default, the block does not create a timeseries object. Instead, it exports the simulation data as a MATLAB array.
However, you can easily convert this data into a timeseries object if you need to work with it as a timeseries. Here is how you can do that:
1. Configure the "To Workspace" Block:
  • Open your Simulink model.
  • Locate the "To Workspace" block that you want to use to capture data.
  • Double-click on the block to open its properties dialog.
2. Configure the "To Workspace" Block Options:
  • In the "To Workspace" block dialog, make sure the "Save format" option is set to "Array."
  • You can specify a variable name in the "Variable name" field to assign a name to the exported MATLAB variable. For example, you can name it something like myData.
3. Run the Simulation:
4. Convert the Data to Timeseries:
  • After the simulation has completed, you can convert the exported data (stored in the ‘myData variable) into a timeseries object using MATLAB code.
You can see the below mentioned sample code for your reference:
% Assuming you have a variable named myData in your workspace
% Convert the data into a timeseries object
time = myData(:, 1); % Assuming the time values are in the first column
data = myData(:, 2:end); % Assuming the data columns start from the second column
myTimeseries = timeseries(data, time);
I hope this helps.
Regards
Amish

Categories

Find more on Interactive Model Editing in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!