Main Content

dsave

Save workspace distributed arrays and Composite objects

    Description

    example

    dsave filename saves all variables in the current workspace, including distributed arrays and Composite objects, to the file with the name filename. If you do not specify an extension for filename, the function assumes the extension is .mat.

    example

    dsave filename variables saves the specified variables to the file with the name filename.

    The function does not support wildcards, nor the -regexp option.

    example

    dsave(filename) performs the same operation as dsave filename.

    For example, these function calls are equivalent:

    dsave("test.mat")
    dsave test.mat
    dsave(filename,variables) performs the same operation as dsave filename variables.

    Examples

    collapse all

    List the variables in the workspace.

    whos
      Name             Size                Bytes  Class          Attributes
    
      Constant       500x500             2000000  double                   
      client        1000x1000            8000000  double                   
      filename         1x1                   166  string                   
      scores          34x26                45886  distributed              
      worker           1x6                   713  Composite                
    

    Save all variables in the workspace, including distributed arrays and Composite objects, to a MAT file with the name fname.

    dsave fname.mat

    If filename is a variable, you can use the function form of the syntax.

    filename = "fname.mat";
    dsave(filename)

    List the variables in fname.

    whos -file fname.mat
      Name                  Size                Bytes  Class     Attributes
    
      Constant            500x500             2000000  double              
      DMAT_MANIFEST         1x1                 13259  struct              
      client             1000x1000            8000000  double              
      filename               -                    166  string              
      scores               34x26                 3536  uint32              
      worker                1x6                 46510  cell                
    

    Create and save several variables to a MAT file with the name mydatafile.

    Create a distributed array.

    D = rand(1000,"distributed");
    Starting parallel pool (parpool) using the 'Processes' profile ...
    Connected to parallel pool with 6 workers.
    

    Create a Composite object on the client and assign data to worker 1.

    C = Composite;            
    C{1} = magic(20);   

    Create an array in the client workspace.

    X = rand(40);

    Save all three variables to a file with the name mydatafile and store the file in the C:\myFolder\myFile folder.

    dsave C:\myData\mydatafile D C X

    Input Arguments

    collapse all

    Name of the file to save, specified as a string scalar or character vector. If you do not specify filename, the dsave function saves workspace variables to a MAT file named matlab.

    If you do not specify an extension for filename, the dsave function creates a file with the name filename and the .mat extension.

    If filename does not include a full path, the dsave function saves the file to the current folder. To save the file to a different folder, specify the full or relative path to the folder in filename. You must have permission to write to the file.

    Example: "myFile.mat2 specifies the name of the file.

    Example: C:\myFolder\myFile.mat specifies the full path to the folder.

    Data Types: char | string

    Names of variables to save, specified as one or more string scalars or character vectors.

    The dsave function does not support wildcards, nor the -regexp option.

    Data Types: char | string

    Limitations

    • dsave does not support saving sparse distributed arrays.

    Version History

    Introduced in R2010a