An interactive introduction to MATLAB

(Jeff_L) #1
2.1simple 2d plotting 23

Importing data from external sources
You can import data from other programs intoMATLABusing the Copy
→ Paste method, or using the Import Data Wizard , found at File → Import
Data... , for Microsoft Excel data, Comma-separated value files and more. There
are also functions,xlsreadandxlswrite.

2.1.1 Multiple plots in one Figure Window


Thesubplotcommand can be used to display a number of different plots in
a single Figure Window, as shown in Figure 6. Thesubplotcommand takes
three arguments that determine the number and location of plots in the Figure
Window. For example,subplot(2,2,1)specifies that the Figure Window will
be divided into 2 rows and 2 columns of plots, and selects the first subplot to
plot into. Listing 2.2 shows an example of usage of thesubplotcommand.
Listing 2.2: Using thesubplotcommand
1 >> x = linspace(0,2pi,50);
2 >> subplot(2,2,1), plot(x,sin(x)), xlabel('x'), ylabel('sin(x)');
3 >> subplot(2,2,2), plot(x,cos(x)), xlabel('x'), ylabel('cos(x)');
4 >> subplot(2,2,3), plot(x,sin(2
x)), xlabel('x'), ylabel('sin(2x)');
5 >> subplot(2,2,4), plot(x,cos(2*x)), xlabel('x'), ylabel('cos(2x)');


Figure 6: Example of subplots
Free download pdf