DataSet vs ModelDataLogs data retrieval

3 次查看(过去 30 天)
I'm converting tests from MATLAB 2011A to 2018B. THe post-processing uses the statements:
With sim output in ModelDataLogs:
logsout = evalin('base','logsout'); % Get logsout from workspace
log.unpack('all'); % unpack signal logs
time = ([1 4.5 5 6 9.75-(1/60) 15.2 20 24 29.9 30 37 58 62 66 72 74.8 80 81 85 90 145 145.2 150 153.6]*60)+1;
time = double(time);
.
.
.
if var1.Data(time(1)) == 0
.
.
.
What is the conversion to the DataSet format to do the same processing?
Using
logsout.getElement(1)
gives the result:
Simulink.SimulationData.Signal
Package: Simulink.SimulationData
Properties:
Name: 'var1'
PropagatedName: ''
BlockPath: [1×1 Simulink.SimulationData.BlockPath]
PortType: 'outport'
PortIndex: 1
Values: [1×1 timeseries]
How do I get the value for a given variable name and time?
Addendum:
The output structure is 2 columns : time and data
I was able to get the format for retrieving a value when I know the index.
[dsout, idx] = find(logsout,'Name', 'var1')
gives me a 22
logsout.getElement('var1').Values.Data(22)
gives me the value.
The next problem is finding the index for a certain time value
i.e What is the index when time = 1.1067
I need to find
logsout.getElement('var1').Values.Data(index of time =1.1067)

回答(1 个)

Sara Nadeau
Sara Nadeau 2019-4-3
Hi Cynthia!
The Dataset object contains Signal objects, and the data in the Signal object - what you describe as 'the output structure' - is actually a timeseries object.
Each object - Dataset, Signal, and timeseries - has a set of functions/methods you can use to operate on that object.
I am not sure that the line you use to get the index of 22 is doing what you intend.
Take a look at the getsampleusingtime function for the timeseries object. I think this might work for you. You pass in a timeseries object (which you access using logsout.getElement(elidx).Values) and time values, and the return is a timeseries object where the data includes only the values for the specified time, which you can then check against your test criteria.
I hope this helps!
  1 个评论
Cynthia Fallon
Cynthia Fallon 2019-4-3
This is what I have:
logsout = evalin('base','logsout');
This contains 197 Simulink.SimulationData.Signal arrays (each with a unique name))
time = [1.0 4.5 5.0 6.0 9.75 15.2 20.0 24.0 29.9 30.0 37.0 58.0 62.0 66.0 72.0 74.8 80.0 81.0 85.0 90.0 145.0 145.2 150.0 153.6];
time_idx = [61 271 301 361 586 913 1201 1441 1795 1801 2221 3481 3721 3961 4321 4489 4801 4861 5101 5401 8701 8713 9001 9217];
The time values wanted are 9.75, and 66.0
matching time indices are 586 and 3961
Each Simulink.SimulationData.Signal entry of logsout contains a timeseries entry containing a
table with 2 columns
the time column has 9300 entries, each incrementied by 0.0167 sec
The data colmnn has the signal value at that time
Inorder to get the correct data for the 9.75 sec signal, I used :
logsout.getElement('signalname').Values.data(time_idx(5))
and the 66.0 sec signal:
logsout.getElement('signalname').Values.data(time_idx(14))
Some of the top level entries ( of 197) contain more than one data column
logsout.getElement('signalname').Values.data(time_idx(14),2)
Another type on entry has 2 indices, where I had to get the first one using find:
[~, BUS_idx] = find(logsout,'Name', 'BUS1');
logsout{BUS_idx}.Values.signalname.data(time_idx(8),1)
I would like to replace the time_idx with an actual time value, but don't know how.
This is what I get with the sampleusingtime function
tsout = getsampleusingtime(logsout.getElement('signalname').Values,80.0)
timeseries
Common Properties:
Name: 'unnamed'
Time: [0x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
Data: [0x0 double]
DataInfo: [1x1 tsdata.datametadata]
More properties, Methods

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Save Run-Time Data from Simulation 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by