This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

tempname

Unique name for temporary file

Syntax

tmpName = tempname
tmpName = tempname(folderName)

Description

example

tmpName = tempname returns a character vector containing a unique path for a temporary file in your system’s temporary folder.

example

tmpName = tempname(folderName) returns a unique path for a temporary file in the specified folder. Specify folderName as a string scalar or a character vector containing the folder name.

Examples

collapse all

Create a temporary file name that has the extension, .dat, by concatenating two character vectors.

tmpName = [tempname,'.dat'];

Create a temporary file name for use in the C:\myTemporaryFiles folder.

tmpName = tempname('C:\myTemporaryFiles');

Create a temporary file name.

filename = tempname;

Create a new file with the temporary file name, and write data to the file.

fileID = fopen(filename,'w');
fwrite(fileID,magic(5));
fclose(fileID);

Limitations

  • In most cases, tempname generates a universally unique identifier (UUID). However, if you run MATLAB® without JVM™ software, then tempname generates a random character vector using the CPU counter and time, which is not guaranteed to be unique. For more information about the MATLAB startup option that does not load JVM software, see Commonly Used Startup Options.

Introduced before R2006a