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

조회 수: 3 (최근 30일)
Florian Rössing
Florian Rössing 2021년 10월 26일
편집: Alvaro 2022년 11월 28일
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: https://de.mathworks.com/help/simulink/slref/simulink.simulationdata.datasetref-class.html
As also described here: https://de.mathworks.com/help/simulink/ug/stream-input-data-for-a-parallel-simulation.html 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"));
numTestCases=length(Store.Data);
for i=1:numTestCases
inputData(i)=Simulink.SimulationData.DatasetRef(append(path,"test.mat"),sprintf("Data{%i}",i));
end
And Store beeing:
Store =
matlab.io.MatFile
Properties:
Properties.Source: 'path\test.mat'
Properties.Writable: false
Properties.ProtectedLoading: false
Data: [20x1 cell]
Methods
Has someone here an idea how to avoid using eval to just create the datasets as Data1,Data2 etc?
Cheers and thank you
  댓글 수: 1
Alvaro
Alvaro 2022년 11월 28일
편집: Alvaro 2022년 11월 28일
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);
end
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.
https://www.mathworks.com/help/matlab/ref/cell2struct.html

댓글을 달려면 로그인하십시오.

답변 (1개)

Smattering_Applause
Smattering_Applause 2022년 6월 23일
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.

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by