Load nonfinite (Inf or NaN) data into simulink simulation
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Evan Wouters
el 13 de Dic. de 2022
Respondida: Guilherme Costa Nascimento
el 15 de Nov. de 2023
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 comentarios
Simulant
el 23 de En. de 2023
I am testing safety relevant requirements and software components. These tests include robustness tests where inputs get not finite numbers.
Respuestas (2)
Sachin Lodhi
el 30 de Ag. de 2023
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 comentario
Kyle
el 14 de Nov. de 2023
Editada: Kyle
el 14 de Nov. de 2023
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
el 15 de Nov. de 2023
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 comentarios
Ver también
Categorías
Más información sobre Simulink Functions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!