{"id":99,"date":"2010-06-22T20:19:31","date_gmt":"2010-06-22T20:19:31","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/2010\/06\/22\/how-to-customize-the-simulink-scope\/"},"modified":"2010-06-22T20:19:31","modified_gmt":"2010-06-22T20:19:31","slug":"how-to-customize-the-simulink-scope","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2010\/06\/22\/how-to-customize-the-simulink-scope\/","title":{"rendered":"How to customize the Simulink Scope!"},"content":{"rendered":"<style type=\"text\/css\">\r\n\/* Publisher style MATLAB code *\/ \r\n\r\npre.codeinput {\r\n  background: #EEEEEE;\r\n  padding: 10px;\r\n}\r\n@media print {\r\n  pre.codeinput {word-wrap:break-word; width:100%;}\r\n} \r\n\r\nspan.keyword {color: #0000FF}\r\nspan.comment {color: #228B22}\r\nspan.string {color: #A020F0}\r\nspan.untermstring {color: #B20000}\r\nspan.syscmd {color: #B28C00}\r\n\r\npre.codeoutput {\r\n  color: #666666;\r\n  padding: 10px;\r\n}\r\n\r\npre.error {\r\n  color: red;\r\n}\r\n<\/style>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/guy_rouleau_small.png\" alt=\"Blogger, Guy Rouleau\"\/> By <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/31651\">Guy Rouleau<\/a><\/p>\r\n\r\n<p>As we all know, there is a tool for each job. You can hit a nail with a screwdriver, but the job is easier with a hammer. It\u2019s the same thing to display Simulink data. One common question I receive in technical support is how to customize the <a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/simulink\/slref\/floatingscope.html\">Simulink Scope<\/a>. My answer to this question is simple: Do not customize the Simulink Scope\u2026 use <a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/simulink\/slref\/simplot.html\"><tt>simplot<\/tt><\/a>.<\/p>\r\n\r\n<p>With <tt>simplot<\/tt>, you can easily take the data from a Simulink Scope that looks like this:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2010Q2\/SimulinkScope.png\" alt=\"Simulink Scope\" \/><\/p>\r\n\r\n<p>And create a MATLAB figure with annotations, legend and labels.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2010Q2\/SimplotFigure.png\" alt=\"Figure generated by simplot\" \/><\/p> \r\n\r\n<p>The Simulink Scope is an optimized display designed to run fast during simulation. Its job is to show signals while the simulation is running. For post-simulation analysis, creating reports and presentations, a MATLAB figure is more appropriate. The <tt>simplot<\/tt> function helps by plotting simulation data in a MATLAB figure that looks like the Simulink Scope.<\/p>\r\n\r\n<p>To plot the output of a Simulink model in a MATLAB figure, the first step is to save the data to the MATLAB workspace using one of these 3 options:<\/p>\r\n\r\n<UL>\r\n<LI>The \u201cSave Data to Workspace\u201d option of Simulink Scopes\r\n<LI><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/simulink\/slref\/toworkspace.html\">To Workspace<\/a> blocks\r\n<LI>Root-level <a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/simulink\/slref\/outport.html\">Outport<\/a> blocks\r\n<\/UL>\r\n\r\n<p>To create the figure above, I saved the output of a Scope block to the variable ScopeData:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2010Q2\/ScopeParameters.png\" alt=\"Simulink Scope parameters\" \/><\/p>\r\n\r\n<p>After simulating the model, I used <tt>simplot<\/tt> to create the figure:<\/p>\r\n\r\n<p><pre class=\"codeinput\">\r\nsimplot(ScopeData)\r\nlegend(<span class=\"string\">'Position'<\/span>,<span class=\"string\">'Velocity'<\/span>)\r\nannotation(<span class=\"string\">'ellipse'<\/span>,[0.68  0.25  0.15  0.12],<span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'EdgeColor'<\/span>,<span class=\"string\">'red'<\/span>,<span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'LineWidth'<\/span>,3);\r\nannotation(<span class=\"string\">'textarrow'<\/span>,[.5 .68],[.2 .3],<span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'TextEdgeColor'<\/span>,<span class=\"string\">'none'<\/span>,<span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'TextLineWidth'<\/span>,3,<span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'TextBackgroundColor'<\/span>,[1 .9 .8],<span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'FontSize'<\/span>,12,<span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'Color'<\/span>,<span class=\"string\">'red'<\/span>,<span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'LineWidth'<\/span>,3,<span class=\"keyword\">...<\/span>\r\n    <span class=\"string\">'String'<\/span>,<span class=\"string\">'I want to show this'<\/span>);\r\n<\/pre><\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>How do you visualize the data coming out of your simulations?<\/p>","protected":false},"excerpt":{"rendered":"<p>\r\n\/* Publisher style MATLAB code *\/ \r\n\r\npre.codeinput {\r\n  background: #EEEEEE;\r\n  padding: 10px;\r\n}\r\n@media print {\r\n  pre.codeinput {word-wrap:break-word; width:100%;}\r\n} \r\n\r\nspan.keyword {color:... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2010\/06\/22\/how-to-customize-the-simulink-scope\/\">read more >><\/a><\/p>","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,67,33],"tags":[141],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/99"}],"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\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=99"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/99\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}