{"id":5123,"date":"2016-02-28T23:24:47","date_gmt":"2016-02-29T04:24:47","guid":{"rendered":"https:\/\/blogs.mathworks.com\/simulink\/?p=5123"},"modified":"2016-02-29T09:41:49","modified_gmt":"2016-02-29T14:41:49","slug":"comparing-runs-in-sdi","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2016\/02\/28\/comparing-runs-in-sdi\/","title":{"rendered":"Comparing Runs in SDI"},"content":{"rendered":"<p>Today I upgraded a large model to the latest release of MATLAB. I found a trick to compare the results before and after the update that I thought I should share.<\/p>\r\n\r\n<p><strong>Different Results<\/strong><\/p>\r\n\r\n<p>To validate that the model simulates as expected, I decided to log many signals, and compare them. For that, I saved the <a title=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/simulink.simulationoutput-class.html (link no longer works)\">Simulink.SimulationOutput<\/a> generated by the model in each release, and imported those in the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/simulation-data-inspector-overview.html\">Simulation Data Inspector<\/a>. <\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q1\/SDI_import.png\" alt=\"Importing data in SDI\" \/><\/p>\r\n\r\n<p>I quickly realized that the results were not matching. This is typical, with floating-point numbers it is usually a bad idea to do a comparison and expect perfect match. Due to floating point round-off errors, it is more appropriate to see if the difference between the signals compared is within a certain tolerance.<\/p>\r\n\r\n<p><strong>Adjusting the Tolerances<\/strong><\/p>\r\n\r\n<p>In the Runs view, it is possible to specify the tolerances used to decide if a signal passes or fails the comparison.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q1\/SDI_tolerance.png\" alt=\"Specifying tolerances in SDI\" \/><\/p>\r\n\r\n<p>Now you might ask: <em>If I want to compare a thousand signals to see if the difference for each of them is within 1%, do I need to set them one by one?<\/em><\/p>\r\n\r\n<p><strong>Specifying the Tolerances Programmatically<\/strong><\/p>\r\n\r\n<p>This is where the Simulation Data Inspector <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/record-and-inspect-signal-data-programmatically.html\">programmatic API<\/a> becomes useful.<\/p> \r\n\r\n<p>With the few lines of code below, it is possible to access the runs, the signals in each run, and get or set their properties:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q1\/SDI_API.png\" alt=\"Specifying tolerances in SDI Programamtically\" \/><\/p>\r\n\r\n<p>What I find convenient is that the API works directly on the open Simulation Data Inspector window. This means that I can immediatly go back to the Simulation Data Inspector, run the comparison and observe how close I am to the specified tolerances.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q1\/SDI_finalCompare.png\" alt=\"Comparison\" \/><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>Give this a try and let us know what you think by leaving a <a href=\"https:\/\/blogs.mathworks.com\/simulink\/?p=5123&#comment\">comment here<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q1\/SDI_finalCompare.png\" onError=\"this.style.display ='none';\" \/><\/div><p>Today I upgraded a large model to the latest release of MATLAB. I found a trick to compare the results before and after the update that I thought I should share.\r\n\r\nDifferent Results\r\n\r\nTo validate... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2016\/02\/28\/comparing-runs-in-sdi\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[121,24],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5123"}],"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=5123"}],"version-history":[{"count":10,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5123\/revisions"}],"predecessor-version":[{"id":5133,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5123\/revisions\/5133"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=5123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=5123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=5123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}