Simulation with large Data and Simulation​Data.Datas​etRef Objects; Avoiding eval

2 views (last 30 days)
Hi everyone,
for my PhD project I need to run simulations in Simulink. In a Monte Carlo Approach I want to simulate many inputs (order of several 100) that I randomly generate. As these Signal Timeseries' require a lot of Memory, so I opted for using DatasetRef Objects:
As also described here: I want to stream my Data. In the example however they have their Datasets for simulations named Road1, Road2 etc, which I have read is bad practice, so I want to avoid it.
I already learned, that I can save my data as a Cell Array of datasets that each contain a timeseries with input data. However I cannot create DatasetRef Object from those entries to hand over to parsim, as the Simulink.SimulationData.DatasetRef() function requires a variable name as an input, but does not accept "Data{i}" as a variable name.
Unfortunately the Data is to large for upload but my code would look like this:
Store = matfile(append(path,"test.mat"));
for i=1:numTestCases
And Store beeing:
Store =
Properties.Source: 'path\test.mat'
Properties.Writable: false
Properties.ProtectedLoading: false
Data: [20x1 cell]
Has someone here an idea how to avoid using eval to just create the datasets as Data1,Data2 etc?
Cheers and thank you
  1 Comment
Alvaro on 28 Nov 2022
Edited: Alvaro on 28 Nov 2022
You can look at what is loaded in the example given in the documentation that you linked by executing
structExample = load('suspn_3dof_test_cases.mat')
and you can see that it is not a cell array of datasets but a struct with fields Road1, Road2, etc.
It is possible to dynamically add fields to structs:
For example, see the struct generated by this code.
for i = 1:10
road = strcat('Road',num2str(i));
myStruct.(road) = rand(1,3);
Could you explain further why generating a struct in this manner would cause any issues?
Alternatively, you could consider converting your cell array to an struct using cell2struct.

Sign in to comment.

Answers (1)

Smattering_Applause on 23 Jun 2022
If you can make it a cell array you can make it a struct, then save the struct in that method and load and then you'll have variable names without eval.


Find more on Simulink Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!