DataSet vs ModelDataLogs data retrieval

조회 수: 3 (최근 30일)
Cynthia Fallon
Cynthia Fallon . 2019년 4월 2일
댓글: Cynthia Fallon . 2019년 4월 3일
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?
gives the result:
Package: Simulink.SimulationData
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?
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
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 :
and the 66.0 sec signal:
Some of the top level entries ( of 197) contain more than one data column
Another type on entry has 2 indices, where I had to get the first one using find:
[~, BUS_idx] = find(logsout,'Name', 'BUS1');
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)
Common Properties:
Name: 'unnamed'
Time: [0x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
Data: [0x0 double]
DataInfo: [1x1 tsdata.datametadata]
More properties, Methods

댓글을 달려면 로그인하십시오.


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