Clear Filters
Clear Filters

How to extract many Timeseries data from large object?

12 views (last 30 days)
Hello All,
I have simulation data results from Simscape/Simulink in the form of an "out" object (attached sample). The object is composed of 18 timeseries. I have to do some post-processing to each of the data series. Currently, since it was an easy copy/paste job, I manually create a variable based on the name of each timeseries, extract it from the out object, and minuplate the data so that it's conducive to plotting.
However, I'm about to have a significantly larger data set to deal with that includes hundreds of timeseries in total. I'm hoping there is a way to write a command to create each variable and do the data manipulation to every timeseries in the out object without having to manually do it series by series.
Any suggestions? You'll find a sample out object attached as well as a .m with my current data extraction and manipulation method.
Thanks in advance; this is all new to me!

Accepted Answer

Pratyush Swain
Pratyush Swain on 19 Apr 2024
Edited: Pratyush Swain on 19 Apr 2024
Hi kylen,
I see you require an efficient manner to obtain all the timeseries objects without having to create variable everytime. You can leverage the "properties" function in MATLAB to retreive all the properties in simulation output and iterate over it.Please refer to the workflow below:
% Initialize a struct to hold all the processed timeseries data
processedData = struct;
% Using the properties function to list out the properties %
props = properties(out);
% Loop through each property
for i = 1:length(props)
propName = props{i};
% Check if the current property is a timeseries, only then process it
if isa(out.(propName), 'timeseries')
% Extract the timeseries data
currentData = out.(propName).Data;
% Performed the same operation you did in your sample code, you can
% modify this step as per your need
manipulatedData = squeeze(sum(currentData, 2));
% You can store the processed data in the struct,with the property
% name being the key
processedData.(propName) = manipulatedData;
end
end
I have tested the workflow with your given data and verified "processedData" contains all the time series objects, you can leverage this to access the retreived & processed data from simulation.
Hope this helps.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!