Load nonfinite (Inf or NaN) data into simulink simulation
19 次查看(过去 30 天)
显示 更早的评论
Before R2022b it was possible to directly load a timeseries with nonfinite data into a Simulink model. Either by loading it directly from the workspace via the Data Import/Export tab of the Configuration Parameters, or by using a similar approach using a 'From Workspace' block.
As of R2022b the support for the following types is dropped: Simulink.Timeseries, Simulink.TsArray, Simulink.SubsysDataLogs, ScopeDataLogs, and StateflowDataLogs.
This means that I have to search for a new way to load nonfinite data into my model. The Simulink.Timeseries documentation suggests to use a Simulink.SimulationData.Dataset. Unfortunately this doesn't seem to be a valid option, as it throws the following error: "The Data property of timeseries must be a built-in numeric, logical, fixed point or enumerated type. Data must be finite (not Inf or NaN)."
What other options are available to load data into a simulation, if the data must be able to contain Inf or NaN?
4 个评论
Simulant
2023-1-23
I am testing safety relevant requirements and software components. These tests include robustness tests where inputs get not finite numbers.
回答(2 个)
Sachin Lodhi
2023-8-30
Hi Evan, I understand that you are trying to load timeseries data in Simulink. Since “Simulink.Timeseries" is dropped in R2022b, you can use "Simulink.SimulationData.Dataset" to load data containing Inf or NaN as shown in the following example code:
% Create sample time values
time = 0.1:0.1:1;
% Create sample data vectors with NaN and inf values
data1 = [1, 2, NaN, 4, 5, Inf, 7, 8, 9, 10];
% Create timeseries objects
ts1 = timeseries(data1, time);
% Create a Simulink.SimulationData.Dataset object
dataset = Simulink.SimulationData.Dataset;
% Add timeseries objects to the dataset
dataset = dataset.addElement(ts1, 'Timeseries1');
The following are the other workarounds to handle Inf or NaN values in your data:
- Replace Inf or NaN values: Before adding the data to the "Simulink.SimulationData.Dataset", you can replace any Inf or NaN values with appropriate values or placeholders. For example, you can replace them with a large number or a specific value that represents missing data.
- Use a different data type: If you need to preserve Inf or NaN values in your dataset, you can consider using a different data type that supports them, such as cell arrays or structures. You can create a cell array or structure to store your timeseries objects along with any additional metadata.
The above workarounds can help you handle Inf or NaN values effectively within your dataset.
You can also use the "From Workspace" Block. I recommend you refer to the following documentation page to know more about loading data using the “From Workspace” block:
I hope this helps you import timeseries data.
1 个评论
Kyle
2023-11-14
编辑:Kyle
2023-11-14
This does not solve this issue, which is that when the model is actually run with the dataset:
simIn = Simulink.SimulationInput(mdl);
simIn = setExternalInput(simIn,dataset);
sim(simIn)
an error will be thrown. It does not appear that a model can be run with a dataset that contains Inf or NaN values. Is there any other way to programmatically set the external inputs for a model that contains multiple input ports?
Guilherme Costa Nascimento
2023-11-15
The only way that I know of to bring in NaN and Inf data into Simulink is with the Playback block, available starting in R2022b: https://www.mathworks.com/help/simulink/slref/playback.html
Other loading blocks, such as the Signal Editor, From Workspace, and Inport blocks, do not support loading Inf or NaN values. I believe this has been the case since R2016b.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!