cs205-fall08 Chapter 4: MATLAB functions / Textbook sample codes

These codes are available for you to copy from the instructor account:
cp ~stewart/cs205/ch4*/* .
Notice the UNIX wildcards making the directory names simpler to deal withd

4.1 Some Common functions
Mathworks search MATLAB Function Reference

This link was discovered using Xwin32 -> Rohan and firing up
matlab&
and using the Help panel of the MATLAB Desktop.

fig4_1.m
demonstrates the exponential (exp), hyperbolic sine (sinh) and hyperbolic cosine (cosh).
fig4_2.m
demonstrates the functions arc cosine (acos), asin and atan.
Instructor will also use the MATLAB command window to add a title to the figure.

4.2 Importing and Exporting data
Many fields of science generate large amounts of data that may need to be analyzed with a tool like MATLAB. The data can be in ASCII (human-readable text) or in binary (raw machine format). Binary is more efficient in storage space and in the "precision" of the values, i.e. not rounded off to a chosen number of digits. The MATLAB command save and load are best to use to save data between MATLAB sessions. Our text starts with an example of exporting text data
save myData.txt A -ascii
You reverse this operation using the save command, but note that is the array A has been saved in myData.txt (as above), then
load myData.txt
creates a variable in the workspace with the same name as the file, but missing the extension (.txt). If you want to have a different variable name, then use
A = load('myData.txt')

Your program can export binary data with
save filename x y z
creating the file filename.mat in MATLAB proprietary binary format, so that the data can only be read and manipulated by MATLAB.

MATLAB has an import Wizard for interactive sessions, but we will not go into this due to our focus on writing MATLAB code to solve problems.

4.2.6 Low-level file I/O functions
Code fragment in text demonstration writing binary data. Note the comments in the code describing the individual steps.
writer.m writing binary data with the operating system calls.

reader.m reading binary data with the operating system calls.

changer.m an elaborate example that can change binary data in a file.