Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Include Page
MATLAB Google Analytics
MATLAB Google Analytics
Include Page
Spring-Mass System - Panel
Spring-Mass System - Panel

Step 3: Plotting

Let's visualize our results by making a plot of the mass position x vs. time using the steps shown in the video below.

Wiki Markup
{html} <iframe width="600" height="338" src="//www.youtube.com/embed/ixSPeMxjODw?rel=0" frameborder="0" allowfullscreen></iframe> {html}


Create Professional-Looking Plot

We'll make a few tweaks to the plot to prettify it and make it look more professional. We'll do this using the following template.

figure(1); %Create figure #1
clf; %Clear current figure
h=plot( , ,' ');
set(h,'LineWidth',2); %Set linewidth for curve
set(gca,'Box','on','LineWidth',2,...
   'FontName','Helvetica',...
   'FontSize',14); %Set axis properties
xlabel('');
ylabel('');
title('');
axis square; %Make axis box square


The following video shows you how to implement this template.

Wiki Markup
{html} <iframe width="600" height="338" src="//www.youtube.com/embed/6i0-X9h9bjM?rel=0" frameborder="0" allowfullscreen></iframe> {html}


Note that we use the variable h for the plot handle in the above video. But we have also used h for the time step. Oops! In this case, this doesn't cause an error since plotting occurs at the end. But it'd be better to call the plot handle, say, hplot in your code.

We next change the axis limits from the default using the axis function so that our curve fills up more of the plot area.

Wiki Markup
{html} <iframe width="600" height="338" src="//www.youtube.com/embed/E77XSRcjfcE?rel=0" frameborder="0" allowfullscreen></iframe> {html}


Add Analytical Solution to Plot

First, we form the necessary arrays from the analytical solution.

Wiki Markup
{html} <iframe width="600" height="338" src="//www.youtube.com/embed/DAlTSfTfJl0?rel=0" frameborder="0" allowfullscreen></iframe> {html}


Second, we add a curve corresponding to the analytical solution to our figure.

Wiki Markup
{html} <iframe width="600" height="338" src="//www.youtube.com/embed/k9cojj_oETU?rel=0" frameborder="0" allowfullscreen></iframe> {html}


Lastly, we add a legend to label the curves.

Wiki Markup
{html} <iframe width="600" height="338" src="//www.youtube.com/embed/trTvzt3cVIo?rel=0" frameborder="0" allowfullscreen></iframe> {html}



Go to Step 4: Function Creation

Go to all MATLAB Learning Modules