12.04.2015 Views

Solving Problems in Dynamics and Vibrations Using MATLAB ...

Solving Problems in Dynamics and Vibrations Using MATLAB ...

Solving Problems in Dynamics and Vibrations Using MATLAB ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

8<br />

then the counter must be <strong>in</strong>cremented such that, the flow of comm<strong>and</strong> does not enter the ‘if’<br />

loop.<br />

% Example to show the use of the hold comm<strong>and</strong><br />

counter = 0;<br />

if (counter ==0)<br />

hold;<br />

end<br />

counter = counter + 1;<br />

Here the ‘hold’ comm<strong>and</strong> is executed only if the value of the counter is equal to zero. In this way<br />

we can make sure that the plots are held. The drawback of this procedure is that we cannot toggle<br />

the ‘hold’ to off.<br />

Plott<strong>in</strong>g Techniques<br />

The plot function has different forms depend<strong>in</strong>g on the <strong>in</strong>put arguments. For example, if y is a<br />

vector, plot (y) produces a l<strong>in</strong>ear graph of the elements of y versus the <strong>in</strong>dex of the elements of y.<br />

If you specify two vectors as arguments, plot (x,y) produces a graph of y versus x.<br />

Whenever a plot is drawn, title’s <strong>and</strong> a label’s for the x axis <strong>and</strong> y axis are required. This is<br />

achieved by us<strong>in</strong>g the follow<strong>in</strong>g comm<strong>and</strong>.<br />

To <strong>in</strong>clude a title for a plot use the follow<strong>in</strong>g comm<strong>and</strong><br />

title (‘Title’)<br />

For the x <strong>and</strong> y labels, use<br />

xlabel(‘ label for the x-axis’)<br />

ylabel(‘label for the y-axis’)<br />

Always remember to plot the data with the grid l<strong>in</strong>es. You can <strong>in</strong>clude the grid l<strong>in</strong>es to your<br />

current axes by <strong>in</strong>clud<strong>in</strong>g the follow<strong>in</strong>g comm<strong>and</strong> <strong>in</strong> your code.<br />

grid on<br />

For more <strong>in</strong>formation about various other plott<strong>in</strong>g techniques, type<br />

help plot<br />

<strong>in</strong> the comm<strong>and</strong> w<strong>in</strong>dow.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!