You are on page 1of 5

IM 512 3.

0 (I) Mathematical Software

Dr. TGI Fernando

September 27, 2011

Dr. TGI Fernando () IM 512 3.0 (I) Mathematical Software September 27, 2011 1/5
Directional Exploration Importing and exporting data

Saving data into a MAT file

Syntax: save filename variable names


E.g.
Execute the following commands:
clear all; (Clear the Matlab workspace (all variables are deleted))
theta = linspace(0, 2*pi, 201);
r = sqrt(abs(2*sin(4*theta)));
x = r.*cos(theta);
y = r.*sin(theta);
f = char(’sqrt(abs(2*sin(4*theta)))’);
save xydata x y f (Save variables x, y and f in a binary (Mat) datafile
xydata.mat).

Dr. TGI Fernando () IM 512 3.0 (I) Mathematical Software September 27, 2011 2/5
Directional Exploration Importing and exporting data

Loading data from a MAT file

Syntax:
load filename (loads all variables stored in filename)
load filename variable names (loads only selected variables)
E.g.
Implement the following commands:
clear all;
whos; (Lists current variables)
load xydata; (Loads all variables in ‘xydata’)
whos plot (x,y), axis(’square’);
f
clear all
load xydata x y (Loads only variables ‘x’ and ‘y’)
whos

Dr. TGI Fernando () IM 512 3.0 (I) Mathematical Software September 27, 2011 3/5
Directional Exploration Importing and exporting data

Saving data into a .m file

Let’s save our data into a .m file.


% TempData: Script file containing data on monthly maximum
temperature
SI No = [1:12]’;
Month = char(‘Jan’, ‘Feb’, ‘Mar’, ‘Apr’, ‘May’, ‘Jun’, ‘Jul’, ‘Aug’, ‘Sep’,
‘Oct’, ‘Nov’, ‘Dec’);
Avg Tmax = [22 25 30 34 36 30 29 27 24 23 21 20]’;

Dr. TGI Fernando () IM 512 3.0 (I) Mathematical Software September 27, 2011 4/5
Directional Exploration Importing and exporting data

Loading data from a .m file

Let’s execute the script file TempData and check the new variables.
clear all
Tempdata (Execute the script file TempData)
whos
Month

Dr. TGI Fernando () IM 512 3.0 (I) Mathematical Software September 27, 2011 5/5

You might also like