Translator Disclaimer
Chapter 4:
Data and Data Files
It is relatively easy to get a MATLAB script to generate data from mathematical functions. However, keeping a particular data set does require a little more work, particularly if the data changes each time a script is run, which will occur if the program uses a random-number generator. Saving data to a file is straightforward, but a little advanced preparation makes the process go more smoothly. Once a file is saved, it can be conveniently retrieved so that it can be used later or passed to another program for further processing. Similarly, it is possible to read data into a program that has been generated in an entirely different program. In any of these cases, data is saved in a data file, and quite often a data file is the most effective way to store the information. Data files can take many forms such as text or image files, but generically, a data file is a place to save data, or a place to read in data. Text files provide easily readable information with very little formatting; however, binary files such as image files often require a special program to be able to read and interpret the data for displaying as a picture. Specialty files such as wordprocessor files and spreadsheet files, to name a few, can also require specific software packages to view their contents. Whether a file requires a special program to view or is just plain data, in general, data files will be in one of two forms, binary or text. Binary files are usually more compact and smaller in size, while text files are usually easier to access and read. In this chapter we will learn how to read and write data files that can be read from text editors and those that can be used to write more-compact MATLAB-only files.
Online access to SPIE eBooks is limited to subscribing institutions.

Back to Top