0.5 Soft Introduction to MATLAB 41
FIGURE 0.18
Plotting four figures in one.
0 50 100
0
0.5
1
0 50 100
0
1
2
3
0 50 100
0
0.5
1
0 50 100
0
1
2
3
axis([0 100 0 3])
subplot(224)
stem(x, z)
axis([0 100 0 3])
Saving and Loading Data
In many situations you would like to either save some data or load some data. The following is one
way to do it. Suppose you want to build and save a table of sine values for angles between 0 and
360 degrees in intervals of 3 degrees. This can be done as follows:
x = 0:3:360;
y = sin(x∗pi/180); % sine computes the argument in radians
xy = [x’ y’]; % vector with 2 columns one for x’
% and another for y’
Let’s now save these values in a file “sine.mat” by using the functionsave(usehelp saveto learn more):
save sine.mat xy
To load the table, we use the functionloadwith the name given to the saved table “sine” (the extension
*.mat is not needed). The following script illustrates this:
clear all
load sine
whos