Dynamic Signal Data Logging
18 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (1 件)
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 件のコメント
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');
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 Center および File Exchange で Save Run-Time Data from Simulation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!