How to extract many Timeseries data from large object?

6 次查看(过去 30 天)
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!

采纳的回答

Pratyush Swain
Pratyush Swain 2024-4-19
编辑:Pratyush Swain 2024-4-19
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Time Series Collections 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by