You are here

The fopen and fclose Functions

9 October, 2015 - 14:47

The first command is used to open or create a file. The basic syntax for fopen is as follows:

fid = fopen(filename, permission)

For example, fo = fopen('output.txt', 'w'); opens or creates a new file named output.txt and sets the permission for writing. If the file already exists, it discards the existing contents.

fclose command is used to close a file. For example, if we type in fclose(fo);, we close the file that was created above.