DataSet vs ModelDataLogs data retrieval
3 views (last 30 days)
Show older comments
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)
0 Comments
Answers (1)
Sara Nadeau
on 3 Apr 2019
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!
See Also
Categories
Find more on Save Run-Time Data from Simulation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!