The tempdir and tempname functions assist in locating temporary data on your system.
Use these functions to create temporary files. Some systems delete temporary files every time you reboot the system. On other systems, designating a file as temporary can mean only that the file is not backed up.
The tempdir function returns the name of the folder that has been designated to hold temporary files on your system. For example, issuing tempdir on The Open Group UNIX® systems returns the /tmp folder.
MATLAB® also provides a tempname function that returns a filename in the temporary folder. The returned filename is a suitable destination for temporary data. For example, if you need to store some data in a temporary file, then you might issue the following command first:
fid = fopen(tempname, 'w');