Dynamic Signal Data Logging

6 次查看(过去 30 天)
Daniel Humke
Daniel Humke 2023-3-29
I am working with a large model utlizing model reference, including multi-instance references, and I have a number of signals that are not enabled for logging. I was initially attempting to explore implementing a data logging override by using the Simulink.SimulationData.ModelLoggingInfo & Simulink.SimulationData.SignalLoggingInfo objects, but found that the signals needed to already be enabled for logging in the model for that approach to work. I am interested in implementing this within a workflow that utilizes the Simulink.SimulationInput objects in order to apply the changes only in a memory space (not the actual model artifacts) and only for that particular simulation run.

回答(1 个)

Meet
Meet 2023-4-3
It sounds like you are looking for a way to enable logging for specific signals in your model without modifying the model itself, and to do so only for a particular simulation run. One approach to achieve this is to use the "Override simulation output options" feature available in the SimulationInput object.
To use this feature, you can create a SimulationOutput object that specifies the signals you want to log and then set that object as the output option for your SimulationInput object. Here's an example code snippet that demonstrates this approach:
% Create a SimulationOutput object with the signals you want to log
output = Simulink.SimulationOutput();
output = output.addLogVars('model_ref_inst1/signal1');
output = output.addLogVars('model_ref_inst2/signal2');
% Create a SimulationInput object for your simulation
input = Simulink.SimulationInput('model_ref');
% Specify the SimulationOutput object as the output option for this simulation
input = input.setVariable('SimOut', output);
% Run the simulation
simOut = sim(input);
In this example, we first create a SimulationOutput object and add the signals we want to log to it. We then create a SimulationInput object for our simulation and set the SimulationOutput object as the "SimOut" variable in the input. When we run the simulation, Simulink will use the output options specified in the "SimOut" variable to override the logging settings for this particular simulation run.
Note that this approach does not modify the model itself, and the logging changes only apply to this particular simulation run. You can also modify the SimulationOutput object to add or remove signals as needed for different simulation runs.
  3 个评论
Daniel Humke
Daniel Humke 2023-4-17
Thank you for the response, this looks very promising to address my needs. I've had some other tasks come up that are higher priority, but I hope to look into validating this solution on my models in the next few weeks; I will provide additional feedback at that time.
Isaac De La Cruz
Isaac De La Cruz 2023-7-19
编辑:Isaac De La Cruz 2023-7-19
I am trying this example in MATLAB R2019b Update 9, and I can't find a method named "addLogVars" in Simulink.SimulationOutput object.
Trying to execute first two lines of code gives an error (this is on R2023a, gives a different error message than R2019b):
% Create a SimulationOutput object with the signals you want to log
output = Simulink.SimulationOutput();
output = output.addLogVars('model_ref_inst1/signal1');
Unrecognized field name "addLogVars".
In R2019b, I get the following:
>> output = Simulink.SimulationOutput();
>> output = output.addLogVars('model_ref_inst1/signal1');
Index exceeds the number of array elements (0).
Looking at the metaclass methods, the "addLogVars" method doesn't appear (R2019b Update 9):
>> mc = ?Simulink.SimulationOutput;
>> disp({mc.MethodList.Name}');
'setCoverageDataFileLocation'
'setDatasetRefMatFileLocation'
'subsasgn'
'subsref'
'numArgumentsFromSubscript'
'SimulationOutput'
'plot'
'isequaln'
'isequal'
'eq'
'find'
'get'
'who'
'removeProperty'
'setUserString'
'setUserData'
'getSimulationMetadata'
'getInternalSimulationDataAndMetadataStructs'
'getElementNames'
'disp'
'setMetadata'
'isprop'
'properties'
'throwIfHasEmptyMetadata'
'privateCheck'
'isPublicPropertyOrMethod'
'locGetArrayStr'
'loadobj'
'setFileSignatures'
'setErrorNoCheck'
'setError'
'empty'
How can we leverage the "Override simulation output options" feature you mentioned? Can you add a working example?
Thanks in advance!

请先登录,再进行评论。

类别

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

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by