# Difference between revisions of "Matlab tips for using less paper."

From Murray Wiki

Jump to navigationJump to search
Line 11: | Line 11: | ||

t = 0:0.1:10; | t = 0:0.1:10; | ||

y1 = sin(t); | y1 = sin(t); | ||

plot(t, y1, 'b') | plot(t, y1, 'b'); | ||

hold on | hold on; | ||

y2 = cos(t); | y2 = cos(t); | ||

plot(t, y2, 'g') | plot(t, y2, 'g'); | ||

hold off | hold off | ||

* '''Subplot''' is another useful Matlab figure command. It allows you to plot multiple small plots on one figure. | * '''Subplot''' is another useful Matlab figure command. It allows you to plot multiple small plots on one figure. | ||

subplot(211) | subplot(211); | ||

plot(t, y1) | plot(t, y1); | ||

subplot(212) | subplot(212); | ||

plot(t, y2) | plot(t, y2) | ||

## Latest revision as of 18:33, 9 November 2006

This problem set (problem 2, in particular) seems to require a lot of plots, so here are some tips for dealing with Matlab images and reducing the size of your problem set:

- If the problem asks for the gain margin and phase margin, but doesn't require a bode plot you don't need to print out the margin plot. You can have the margin command output the numerical values of GM and PM by calling it with output arguments.

[Gm,Pm,Wcg,Wcp] = margin(sys);

Make sure you include this code with your problem set.

- Export your images and put multiple images one each page. In the Figure window go to File > Export Setup... This will open a new window and you should click the Export button. From here you can save the file in a convenient location with a good file format. If you want to put multiple figures in a Microsoft Word document the extension *.png is a good choice. *.eps and *.pdf are other good options. Now that you have the images saved you can put multiple images on a page. For example, in Microsoft Word if you go to Insert > Picture > From File... you can include your figure in a Word document. From here the images can be resized and multiple images can be put on each page. You can even copy your Matlab code in below the image.

- Put multiple lines on the same graph and use a different color or line texture per line. The
**hold on**command can sometimes be useful.

t = 0:0.1:10; y1 = sin(t); plot(t, y1, 'b'); hold on; y2 = cos(t); plot(t, y2, 'g'); hold off

**Subplot**is another useful Matlab figure command. It allows you to plot multiple small plots on one figure.

subplot(211); plot(t, y1); subplot(212); plot(t, y2)

Read the help documentation on subplot for more extensive information.

--Mary Dunlop 10:28, 9 November 2006 (PST)