work with big data for simulations -凯发k8网页登录

main content

work with big data for simulations

simulation of models with many time steps and signals can involve big data that is too large to fit into the ram of your computer. such situations include:

  • logging simulation data (signal logging, output port logging, and state logging)

  • loading input signal data for simulating a model

  • running multiple or parallel simulations

to work with big data for simulations, store the data to persistent storage in a mat-file. using big data techniques for simulations requires additional steps beyond what you do when the data is small enough to fit in workspace memory. as you develop a model, consider logging and loading simulation data without using persistent storage unless you discover that your model has big data requirements that overload memory.

big data workflow

this example is a high-level workflow for handling big data that one simulation produces and that another simulation uses as input. for more detailed information about the major workflow tasks, see:

tip

this example uses a simulationdatastore object for streaming data into a model. alternatively, you can stream a datasetref object directly into a model.

  1. configure two models to log several signals.

  2. simulate the models, logging the data to persistent storage for each model.

    sim(mdl1,'loggingtofile','on','loggingfilename','data1.mat');
    sim(mdl2,'loggingtofile','on','loggingfilename','data2.mat');

    logging that involves big data requires saving the data to persistent storage as a v7.3 mat-file. only the data logged in dataset format is saved to the file. data logged in other formats, such as structure with time, is saved in memory, in the base workspace.

    the data that you log to persistent storage is streamed during the simulation in small chunks, to minimize memory requirements. the data is stored in a file that contains dataset objects for each set of logged data (for example, logsout and xout).

  3. create datasetref objects (dsr1 and dsr2) for specific sets of logged signals. then create simulationdatastore objects (dst1 and dst2) for values of elements of the datasetref objects. this example code creates a simulationdatastore for the 12th element of logsout for the first simulation. for the second simulation, the example code creates a signal with values being a simulationdatastore object for the seventh element of logsout. you can use curly braces for indexing.

    dsr1 = simulink.simulationdata.datasetref('data1.mat','logsout');
    dsr2 = simulink.simulationdata.datasetref('data2.mat','logsout');
    dst1 = dsr1{12};
    dst2 = dsr2{7};
  4. use simulationdatastore objects as an external input for another simulation. to load the simulationdatastore data, include it in a dataset object. the datastore input is incrementally loaded from the mat-file. the third input is a timeseries object, which is loaded into memory as a whole, not incrementally.

    input = simulink.simulationdata.dataset;
    input{1} = dst1; 
    input{2} = dst2;
    ts = timeseries(rand(5,1),1,'name','randomsignals');
    input{3} = ts;
    sim(mdl3,'externalinput','input');
  5. use matlab® big data analysis to work with the simulationdatastore objects. create a timetable object by reading the values of a simulationdatastore object. the read function reads a portion of the data. the readall function reads all the data.

    tt = dst1.values.read;
  6. set the matlab session as the global execution environment (mapreducer) for working with the tall timetable. create a tall timetable from a simulationdatastore object and read a timetable object with in-memory data.

    mapreducer(0);
    ttt = tall(dst1.values);
    

tip

for another example showing how to work with big simulation data, see .

see also

functions

  • | | |

related topics

网站地图