Documentation Center

  • Trial Software
  • Product Updates


Compress files into zip file


entrynames = zip(zipfile,files,rootfolder)


zip(zipfile,files) creates a zip file with the name zipfile from the list of files and folders specified in files. Folders recursively include all of their content.

zip(zipfile,files,rootfolder) specifies the path for files relative to rootfolder instead of the current folder.

entrynames = zip(zipfile,files,rootfolder) returns a string cell array of the names of the files contained in zipfile. Specifying rootfolder is optional.

Input Arguments


String that specifies the name of the zip file. If zipfile has no extension, MATLAB® appends the .zip extension.

If files includes relative paths, the zip file also contains relative paths. The zip file does not include absolute paths.


String or cell array of strings containing the list of files or folders to include in zipfile.

Individual files that are on the MATLAB path can be specified as partial path names. Otherwise an individual file can be specified relative to the current folder or with an absolute path.

Folders must be specified relative to the current folder or with absolute paths. On UNIX® systems, folders can also start with ~/ or ~username/, which expands to the current user's home folder or the specified user's home folder, respectively. The wildcard character * can be used when specifying files or folders, except when relying on the MATLAB path to resolve a file name or partial path name.


String that specifies the root of the paths for the files to zip.

Relative paths in the zip file reflect the relative paths in files, and do not include path information from rootfolder.

Default: current folder ('.')

Output Arguments


Cell array of strings that contain the paths to the files in zipfile. If files includes relative paths, entrynames also contains relative paths.


expand all

Zip a File

Create a zip file of the file membrane.m, which is in the MATLAB general folder. Save the zip file in the current folder.

file = fullfile(matlabroot,'toolbox','matlab','general','membrane.m');

Zip Selected Files

Suppose that your system has a folder named d:/myfiles. Zip the files membrane.m and logo.m, which are on the MATLAB search path, into a file named

myfile = fullfile('d:','myfiles','');

Zip all .m and .mat files in the current folder to the file


Zip a Folder

Suppose that your current folder contains a subfolder named mywork. Zip the contents of all subfolders of mywork, and store the relative paths in the zip file.


Zip Between Folders

Suppose that you have files thesis.doc and defense.ppt in d:/PhD. Zip these files into, one level up from the current folder.


Create Zip Archive of Web Page

Create a zip archive of a Web page.

Locate the list of files at the MATLAB Central File Exchange uploaded within the past 7 days, that contain "Simulink."

filex = '';
params = {'duration','7','term','simulink'};

Save the Web content to a file.


Create a zip archive of the retrieved Web page, using the zip function.


zip creates a zip archive named that contains the file, contains_simulink.html.


To zip files in the Current Folder browser, select the files, right-click to open the context menu, and then select Create Zip File.

See Also

| | | |

Was this topic helpful?