フィルターのクリア

How to extract many Timeseries data from large object?

15 ビュー (過去 30 日間)
Kylen
Kylen 2024 年 4 月 18 日
コメント済み: Kylen 2024 年 4 月 22 日
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.
  1 件のコメント
Kylen
Kylen 2024 年 4 月 22 日
Sir/Ma'am: you are a life saver! Thank you sincerely!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTime Series Collections についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by