{"id":5658,"date":"2016-06-14T09:33:09","date_gmt":"2016-06-14T14:33:09","guid":{"rendered":"https:\/\/blogs.mathworks.com\/simulink\/?p=5658"},"modified":"2016-06-14T09:33:25","modified_gmt":"2016-06-14T14:33:25","slug":"another-good-reason-to-log-simulation-data-in-dataset-format","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2016\/06\/14\/another-good-reason-to-log-simulation-data-in-dataset-format\/","title":{"rendered":"Another Good Reason to Log Simulation Data in Dataset Format"},"content":{"rendered":"<p><em>Today I am happy to welcome guest blogger Mariano Lizarraga Fernandez. A few days ago, Mariano came to me looking for help understanding a Simulink behavior that a user was not able to explain. Once we figured it out, we thought it would be good to share with you.<\/em><\/p>\n<p><strong>Introduction<\/strong><\/p>\n<p> In R2015b we introduced the possibility to save states and outputs in <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016a\/simulink\/slref\/simulink.simulationdata.dataset-class.html (link no longer works)\">Dataset<\/a> format. In R2016a, these capabilities were further extended to log units, and for large amounts of data, to be able to log data directly to a MAT-file. I could list tons of reasons why the Dataset format is more convenient than other options, but for today what I want to share is an example where the dataset format could have helped avoiding lots of confusion.<\/p>\n<p><strong>Serializing Data from frames<\/strong><\/p>\n<p>I was recently helping a customer who was logging <a href=\"https:\/\/www.mathworks.com\/help\/dsp\/ug\/sample-and-frame-based-concepts.html#bso3re7\">frames-based signals<\/a> with a variable-step solver and saving it to the workspace. If the frame-based data was serialized (i.e each frame was stacked on to the last one creating a <tt>n x 1<\/tt> vector) and plotted, the data showed what looked like every once in a while a frame was repeated, causing discontinuities every given number of frames.<\/p>\n<p>Take for instance the following model, which uses a variable-step discrete solver and contains two different sample times. The model is configured to save outputs in the <strong>Structure with Time<\/strong> format:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/frameModel.png\" alt=\"Frames Example 1\" \/><\/p>\n<p>Serializing and plotting the outport's 'Out1' data, one can see the repeated frames:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/frameFigure.png\" alt=\"Frames output\" \/><\/p>\n<p>The <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/data-format-for-logged-simulation-data.html#bs40i1i-7\">Structure with Time documentation<\/a> explains that it contains a single vector of the simulation times. This has two implications:<\/p>\n<ol>\n<li>The time vector contains the union of all sample time vectors used in the model.<\/li>\n<li>For the signal values to be consistent with the time vector, its value must be logged at every sample time contained in the time vector.<\/li>\n<\/ol>\n<p><strong>Using Dataset to Log Data at Different Sample Rates<\/strong><\/p>\n<p>To better understand these implications, let's get rid of the frame and consider the following model which saves 3 ramp signals:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/simpleModel.png\" alt=\"Simple Model\" \/><\/p>\n<p>Let us now run the simulation and log the output of all three outports in two different formats: Structure With Time and Dataset. To see the effect of the <em>single time vector<\/em> of the structure with time format, I like to plot the data using the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/stem.html\">stem<\/a> function.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/signalsFigure.png\" alt=\"Simple model output\" \/><\/p>\n<p>With the Dataset format, each signal is a timeseries object with its own sample time. Whereas for the Structure with Time, since there is only a single time vector, data has to be recorded for all outputs at every sample time.<\/p>\n<p><strong>Now its Your Turn<\/strong><\/p>\n<p>If you are logging simulation data using Structure with Time, I recommend using the Dataset format instead as it is more flexible and gives you independent time vectors. This format also allows you to log <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016a\/simulink\/units.html (link no longer works)\">units<\/a> information, you can log directly to a MAT-file, and can even log multiple values for a single time step, which is useful inside iterator subsystems.<\/p>\n<p>Give it a try and let us know what you think by leaving a <a href=\"https:\/\/blogs.mathworks.com\/simulink\/?p=5658&#comment\">comment here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/signalsFigure.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>Today I am happy to welcome guest blogger Mariano Lizarraga Fernandez. A few days ago, Mariano came to me looking for help understanding a Simulink behavior that a user was not able to explain. Once... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2016\/06\/14\/another-good-reason-to-log-simulation-data-in-dataset-format\/\">read more >><\/a><\/p>\n","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[43,33,16],"tags":[214,215],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5658"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=5658"}],"version-history":[{"count":8,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5658\/revisions"}],"predecessor-version":[{"id":5702,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5658\/revisions\/5702"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=5658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=5658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=5658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}