11.07.2015 Views

MatlabNotes

MatlabNotes

MatlabNotes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Fig. 11: contour plot showing maxima.24 Reading/Writing Data FilesFig. 10: “mesh” and “contour” plots.To locate the maxima of the “f” values on the grid:>> fmax = max(max(f))fmax =0.0886>> kmax = find(f==fmax)kmax =323539>> Pos = [X(kmax), Y(kmax)]Pos =-0.5000 0.60000.5000 -0.6000>> plot(X(kmax),Y(kmax),’*’)>> text(X(kmax),Y(kmax),’ Maximum’)See §13.10 for formatting text and labels.Direct input of data from keyboard becomes impracticalwhen• the amount of data is large and• the same data is analysed repeatedly.In these situations input and output is preferablyaccomplished via data files. We have already describedin Section 9 the use of the commands saveand load that, respectively, write and read the valuesof variables to disk files.When data are written to or read from a file itis crucially important that a correct data formatis used. The data format is the key to interpretingthe contents of a file and must be known in order tocorrectly interpret the data in an input file. Thereare two types of data files: formatted and unformatted.Formatted data files uses format stringsto define exactly how and in what positions of arecord the data is stored. Unformatted storage, onthe other hand, only specifies the number format.The files used in this section are available from theweb sitehttp://www.maths.dundee.ac.uk/software/matlab.shtmlThose that are unformatted are in a satisfactoryform for the Windows version on Matlab (version6.1) but not on Version 5.3 under Unix.Exercise 24.1 Suppose the numeric data is storedin a file ’table.dat’ in the form of a table, asshown below.38

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!