You are here

The diary Function

9 October, 2015 - 14:47

Instead of writing a script from scratch, we sometimes solve problems in the Command Window as if we are using a scientific calculator. The steps we perform in this fashion can be used to create an m-file. For example, the diary function allows us to record a MATLAB session in a file and retrieve it for review. Reviewing the file and by copying relevant parts of it and pasting them in to an m-file, a script can be written easily.

Typing diary at the MATLAB prompt toggles the diary mode on and off. As soon as the diary mode is turned on, a file called diary is created in the current directory. If you like to save that file with a specific name, say for example problem16, type

» diary problem16.txt.

A file named problem16.txt will be created. The following is the content of a diary file called problem16.txt. Notice that in that session, the user is executing the four files we created earlier. The user’s keyboard input and the resulting display output is recorded in the file. The session is ended by typing diary which is printed in the last line. This might be useful to create a record of your work to hand in with a lab or to create the beginnings of an m-file.

    AcetyleneBottle

Vol_total =

    0.4807
AcetyleneBottleInteractive
Enter the radius of acetylene bottle in meters .3
Enter the height of cylinderical part of acetylene bottle in meters 1.5

Vol_total =

    0.4807

AcetyleneBottleInteractiveDisp
This script computes the volume of an acetylene bottle
Enter the radius of acetylene bottle in meters .5
Enter the height of cylinderical part of acetylene bottle in meters 1.6

The volume of the acetylene bottle is
    1.5184

AcetyleneBottleInteractiveDisp1
This script computes the volume of an acetylene bottle:

Enter the radius of acetylene bottle in meters .9
Enter the height of cylinderical part of acetylene bottle in meters 1.9

The volume of the acetylene bottle is 6.3617 cubic meters.
diary