Azzera filtri
Azzera filtri

Load nonfinite (Inf or NaN) data into simulink simulation

40 visualizzazioni (ultimi 30 giorni)
Evan Wouters
Evan Wouters il 13 Dic 2022
Commentato: Enrico il 1 Ott 2024 alle 7:43
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 Commenti
Evan Wouters
Evan Wouters il 23 Gen 2023
My use case is a unit test that verifies that a Simulink model and the code generated from that Simulink model behave similar. So that's not very application specific.
The generated code still supports nonfinite data and so does Simulink, so I want to keep testing this. I made a workaround where the nonfinite data is created in Simulink itself and not imported from the workspace. Then it remains possible to feed this nonfinite data into a (referenced) model or a subsystem.
Simulant
Simulant il 23 Gen 2023
I am testing safety relevant requirements and software components. These tests include robustness tests where inputs get not finite numbers.

Accedi per commentare.

Risposte (2)

Sachin Lodhi
Sachin Lodhi il 30 Ago 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:
  1. 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.
  2. 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 Commento
Kyle
Kyle il 14 Nov 2023
Modificato: Kyle il 14 Nov 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?

Accedi per commentare.


Guilherme Costa Nascimento
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.
  5 Commenti
Guilherme Costa Nascimento
Guilherme Costa Nascimento il 30 Set 2024 alle 15:38
Hi Enrico,
Yes, the Playback block supports enumerations and you can pull straight from a .mat file, without the need for any callbacks. I find that timeseries are the easiest way to work with the Playback block.
Using the Playback block doesn't preclude you from using other methods of bringing in data in the same model. So, for instance, you could still use an Inport to bring in the enumerated data, and then use the Playback block for the data that contains Inf or NaN values.
Hope this helps.

Accedi per commentare.

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by