{"id":363,"date":"2019-11-27T13:32:27","date_gmt":"2019-11-27T05:02:27","guid":{"rendered":"http:\/\/people.utm.my\/razman-ayop\/?p=363"},"modified":"2020-07-30T10:45:08","modified_gmt":"2020-07-30T02:15:08","slug":"plot-from-simulink","status":"publish","type":"post","link":"https:\/\/people.utm.my\/razman-ayop\/plot-from-simulink\/","title":{"rendered":"Plot from Simulink"},"content":{"rendered":"<p>Scope can easily shown you the result of the simuilation. However, it is not clear when the graph from the scope is transfer to the Word document. Here is the step to properly plot graph from Simulink simulation.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-364\" src=\"https:\/\/people.utm.my\/razman-ayop\/wp-content\/uploads\/sites\/2074\/2019\/11\/2019-11-27_125602-300x275.jpg\" alt=\"\" width=\"204\" height=\"187\" \/><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-365\" src=\"https:\/\/people.utm.my\/razman-ayop\/wp-content\/uploads\/sites\/2074\/2019\/11\/2019-11-27_125653-300x270.jpg\" alt=\"\" width=\"300\" height=\"270\" \/><\/p>\n<ol>\n<li>Add &#8220;To workspace&#8221; block into the simulation. [Library&gt;Simulink&gt;Sinks&gt;To Workspace]<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-366\" src=\"https:\/\/people.utm.my\/razman-ayop\/wp-content\/uploads\/sites\/2074\/2019\/11\/2019-11-27_125844.jpg\" alt=\"\" width=\"185\" height=\"125\" \/><\/li>\n<li>Change the variable name according to your specification. Change the &#8220;Save format&#8221; to &#8220;Array&#8221;.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-367\" src=\"https:\/\/people.utm.my\/razman-ayop\/wp-content\/uploads\/sites\/2074\/2019\/11\/2019-11-27_125932-300x283.jpg\" alt=\"\" width=\"300\" height=\"283\" \/><\/li>\n<li>Add &#8220;Clock&#8221; block into the simulation to record the time. [Library&gt;Simulink&gt;Sources&gt;Clock]<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-370\" src=\"https:\/\/people.utm.my\/razman-ayop\/wp-content\/uploads\/sites\/2074\/2019\/11\/2019-11-27_130346.jpg\" alt=\"\" width=\"80\" height=\"93\" \/><\/li>\n<li>Copy the &#8220;To workspace&#8221; block to the signal you want to plot. Connect the &#8220;Clock&#8221; to the &#8220;To workspace&#8221; block.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-371\" src=\"https:\/\/people.utm.my\/razman-ayop\/wp-content\/uploads\/sites\/2074\/2019\/11\/2019-11-27_130642-300x211.jpg\" alt=\"\" width=\"300\" height=\"211\" \/><\/li>\n<li>Run the simulation. All the signals connected to the &#8220;To workspace&#8221; are now available in the MATLAB Workspace area.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-372\" src=\"https:\/\/people.utm.my\/razman-ayop\/wp-content\/uploads\/sites\/2074\/2019\/11\/2019-11-27_130843-243x300.jpg\" alt=\"\" width=\"243\" height=\"300\" \/><\/li>\n<li>Open a new script in MATLAB.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-374\" src=\"https:\/\/people.utm.my\/razman-ayop\/wp-content\/uploads\/sites\/2074\/2019\/11\/2019-11-27_131017.jpg\" alt=\"\" width=\"288\" height=\"246\" \/><\/li>\n<li>Copy this code:<br \/>\n<span style=\"color: #0000ff\"><em>clc;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 %To clear command window<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><span style=\"color: #0000ff\"><span style=\"color: #0000ff\"><em>close all;\u00a0 \u00a0 \u00a0 \u00a0%To close all figure<\/em><\/span><\/span><\/span>&nbsp;<\/p>\n<p><span style=\"color: #0000ff\"><em>subplot(2,1,1)\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 %Use subplot to do multiple plot<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>plot(t,Va);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0%Plot Va against t.<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0%Va and t taken from workspace<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>xlabel(&#8216;Time, t (s)&#8217;);\u00a0 \u00a0 %Label x-axis<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>ylabel(&#8216;Voltage A, V_a (V)&#8217;); %Label y-axis<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>grid on;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0%add grid<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>xlim([0 5]);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0%change the range of x-axis<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>ylim([-0.1 1.1]);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0%change the range of y-axis<br \/>\n<\/em><\/span><span style=\"color: #0000ff\"><em><br \/>\nsubplot(2,1,2)\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0%Use subplot to do multiple plot<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>plot(t,Ia);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0%Plot Ia against t.<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 %Ia and t taken from workspace<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>xlabel(&#8216;Time, t (s)&#8217;);\u00a0 \u00a0 \u00a0%Label x-axis<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>ylabel(&#8216;Current A, I_a (A)&#8217;); %Label y-axis<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>grid on;\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 %add grid<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>xlim([0 5]);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 %change the range of x-axis<\/em><\/span><br \/>\n<span style=\"color: #0000ff\"><em>ylim([-1.1 1.1]);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0%change the range of y-axis<\/em><\/span><\/li>\n<li>The figure produced by the script is better compared to the scope.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-377\" src=\"https:\/\/people.utm.my\/razman-ayop\/wp-content\/uploads\/sites\/2074\/2019\/11\/2019-11-27_132507-300x283.jpg\" alt=\"\" width=\"300\" height=\"283\" \/><\/li>\n<li>To transfer the figure to the Word document, adjust the figure to the desired size. Then &#8220;Edit&#8221;&gt;&#8221;Copy Figure&#8221;. Paste to Word document.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-376\" src=\"https:\/\/people.utm.my\/razman-ayop\/wp-content\/uploads\/sites\/2074\/2019\/11\/2019-11-27_132424-300x275.jpg\" alt=\"\" width=\"300\" height=\"275\" \/><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Scope can easily shown you the result of the simuilation. However, it is not clear when the graph from the scope is transfer to the Word document. Here is the step to properly plot graph from Simulink simulation. Add &#8220;To workspace&#8221; block into the simulation. [Library&gt;Simulink&gt;Sinks&gt;To Workspace] Change the variable name according to your specification. [&hellip;]<\/p>\n","protected":false},"author":24954,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[32],"tags":[],"class_list":["post-363","post","type-post","status-publish","format-standard","hentry","category-research-guidance"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/people.utm.my\/razman-ayop\/wp-json\/wp\/v2\/posts\/363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/people.utm.my\/razman-ayop\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/people.utm.my\/razman-ayop\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/people.utm.my\/razman-ayop\/wp-json\/wp\/v2\/users\/24954"}],"replies":[{"embeddable":true,"href":"https:\/\/people.utm.my\/razman-ayop\/wp-json\/wp\/v2\/comments?post=363"}],"version-history":[{"count":7,"href":"https:\/\/people.utm.my\/razman-ayop\/wp-json\/wp\/v2\/posts\/363\/revisions"}],"predecessor-version":[{"id":453,"href":"https:\/\/people.utm.my\/razman-ayop\/wp-json\/wp\/v2\/posts\/363\/revisions\/453"}],"wp:attachment":[{"href":"https:\/\/people.utm.my\/razman-ayop\/wp-json\/wp\/v2\/media?parent=363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/people.utm.my\/razman-ayop\/wp-json\/wp\/v2\/categories?post=363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/people.utm.my\/razman-ayop\/wp-json\/wp\/v2\/tags?post=363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}