{"id":682,"date":"2012-05-14T20:48:53","date_gmt":"2012-05-15T01:48:53","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=682"},"modified":"2012-05-14T20:48:53","modified_gmt":"2012-05-15T01:48:53","slug":"how-to-load-and-save-bus-signal-data","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2012\/05\/14\/how-to-load-and-save-bus-signal-data\/","title":{"rendered":"How to Load and Save Bus Signal Data"},"content":{"rendered":"<p>In R2012a, the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/slref\/fromworkspace.html\">From Workspace<\/a>, <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/slref\/toworkspace.html\">To Workspace<\/a>, <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/slref\/fromfile.html\">From File<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/toolbox\/simulink\/slref\/tofile.html\">To File<\/a> blocks all support bus signals.  This is an often requested capability, and I have been looking forward to it for a long time.<\/p>\r\n\r\n<p><strong>MATLAB Timeseries<\/strong><\/p>\r\n\r\n<p>In R2012a, most methods for importing and exporting data to and from a model have been standardized to use <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/techdoc\/ref\/timeseriesclass.html\">MATLAB Timeseries<\/a>.<\/p>\r\n\r\n<p>For example, if you open the dialog of the To Workspace, you will see that timeseries is now the default save format:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/ToWorkspaceDialog.png\" alt=\"save formats for the To Workspace block\"><\/p>\r\n\r\n<p>Using MATLAB timeseries offers a lot of advantages as I described in a <a href=\"https:\/\/blogs.mathworks.com\/seth\/2011\/08\/22\/the-dataset-logging-format\/\">previous post on the dataset logging format<\/a>.<\/p>\r\n\r\n<p><strong>Importing Bus Data<\/strong><\/p>\r\n\r\n<p>Let's say I want to import bus data, I create a structure of timeseries:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/createBusData.png\" alt=\"Creating bus data\"><\/p>\r\n\r\n<p>Then I specify the name of the variable or file, and the bus object in the From Workspace or From File dialog.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/FromWSdialog.png\" alt=\"Configuring the From Workspace block to import bus data\"><\/p>\r\n\r\n<p>and we have a model importing buses!<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/busLoadingModel.png\" alt=\"Model importing bus data\"><\/p>\r\n\r\n<p><strong>Exporting Bus data<\/strong><\/p>\r\n\r\n<p>To export bus data, all you need to do do is connect the bus signal to a To Workspace or To File block and ensure the block is configured to use timeseries as save format (the default).<\/p>\r\n\r\n<p>Once the data is in the MATLAB Workspace, you can use all <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2012a\/techdoc\/ref\/f16-48518.html#f16-48710\">timeseries methods<\/a> to process your data.<\/p>\r\n\r\n<p>For example, I can quickly detrend, filter and plot a random signal \"b\", contained inside bus \"busOut\":<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/postProcess.png\" alt=\"processing bus data using MATLAB timeseries\"><\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2012Q2\/displayProcessedData.png\" alt=\"Processed data\"><\/p>\r\n\r\n<p><strong>Now its your turn<\/strong><\/p>\r\n\r\n<p>Are you going to include these new methods of loading and saving bus data in your workflow? Which is be best block pair for loading\/saving buses?  Let us know by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=682&amp;#comment\">comment here<\/a><\/p>\r\n\r\n","protected":false},"excerpt":{"rendered":"<p>In R2012a, the From Workspace, To Workspace, From File and To File blocks all support bus signals.  This is an often requested capability, and I have been looking forward to it for a long... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2012\/05\/14\/how-to-load-and-save-bus-signal-data\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,16],"tags":[266,162,265],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/682"}],"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=682"}],"version-history":[{"count":23,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/682\/revisions"}],"predecessor-version":[{"id":878,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/682\/revisions\/878"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}