save
Matlab Save编辑本段回目录
Save workspace variables to disk
节省磁盘中变量的工作空间 matlab
Graphical Interface 图形界面编辑本段回目录
As an alternative to the save function, select Save Workspace As from the File menu in the MATLAB desktop, or use the Workspace browser.
save功能的选择,是在MATLAB桌面文件菜单下的save工作空间,或者可使用空间浏览器。
Syntax 语法编辑本段回目录
save
save filename
save filename content
save filename options
save filename content options
save('filename', 'var1', 'var2', ...)
matabc
Description 描述编辑本段回目录
save stores all variables from the current MATLAB workspace in a MATLAB formatted file (MAT-file) named matlab.mat that resides in the current working directory. Use the load function to retrieve data stored in MAT-files. By default, MAT-files are double-precision, binary files. You can create a MAT-file on one machine and then load it on another machine using a different floating-point format, and retaining as much accuracy and range as the different formats allow. MAT-files can also be manipulated by other programs external to MATLAB.
save保存了所有来自于当前MATLAB工作空间的变量,并将这些变量保存在一个以matlab.mat命名的格式文件(也就是MAT-file)中,这个文件存在于当前工作目录下。可以通过load函数来检索保存在MAT-files中的数据。MAT-files被默认为是一个双精度的二进制文件。用户可以在一台计算机上创建一个MAT-file,然后在另一台计算机上通过使用一个不同的浮点型格式来下载,并且保持同样的精度和大小。MAT-file也可以被其他与MATLAB无关的程序操作。
save filename stores all variables in the current workspace in the file filename. If you do not specify an extension to the filename, MATLAB uses .mat. The file must be writable. To save to another directory, use a full pathname for the filename.
save filemane 保存了所有在当前工作空间变量文件的文件名。如果用户不指定文件的拓展名,MATLAB就使用 .mat。文件必须是可写的。为了保存另一个目录,请使用文件的完整路径名。
save filename content stores only those variables specified by content in file filename. If filename is not specified, MATLAB stores the data in a file called matlab.mat. See the following table.
save文件名的内容仅仅只包含被文件名指定的内容。如果文件名不详细,MATLAB就会将数据保存在一个名叫matlab.mat的文件中。下面来看一下以下的表格。
Values for content 内容的价值
| Description 描述 matlab |
varlist 表示一个变量或多个变量,变量与变量之间用空格隔开。
| Save only those variables that are in varlist. You can use the * wildcard to save only those variables that match the specified pattern. For example, save('A*') saves all variables that start with A. 仅仅只保存在varlist中的那些变量。用户可使用通配符来保存那些指定模式的变量。比如,save('A*')命令就保存了所有以A开头的变量。
|
-regexp exprlist | Save those variables that match any of the regular expressionsin exprlist. See the Remarks section below. regexp exprlist 就是保存所有符合在exprlist中正则表达式的变量。再来关注一下下面Remarks部分的内容。 |
-struct s | Save as individual variables all fields of the scalar structure s. struct s就是将所有领域内的标量另存为个体变量。
|
-struct s fieldlist | Save as individual variables only the specified fields of structure s. struct s fieldlist 就是只将进行详细说明的结构类型另存为个体变量。
|
In this table, the terms varlist, exprlist, and fieldlist refer to one or more variable names, regular expressions, or structure field names separated by either spaces or commas, depending on whether you are using the MATLAB command or function format. See the examples below: matlab
在上述表格中,varlist, exprlist,和fieldlist指的是一个或多个变量名, 正则表达式或结构域名被各自的空间或逗号隔开,这个取决于你是使用的MATLAB 命令还是函数格式。接下来看一下以下的例子:
Command format:
命令格式
save myfile.mat firstname lastname
Function format:
函数格式
save('myfile.mat', 'firstname', 'lastname')
save filename options stores all variables from the MATLAB workspace in file filename according to one or more of the following options. If filename is not specified, MATLAB stores the data in a file called matlab.mat.
根据一个或多个的以下选项,save filemane options 将保存来自MATLAB工作空间的所有变量。如果文件名没有详细说明,那么MATLAB将数据保存在一个名叫matlab.mat的文件中。 matabc
Values for options 选择的价值依据 | Description 描述
|
-append 设置数据文件的搜索路径
| Add new variables to those already stored in an existing MAT-file. 在已经存在的MAT-file中增加新的变量。 |
-format 格式 | Save using the specified binary or ASCII format. See the section on, MAT-File Format Options, below. 以规定的二进制或ASCII格式保存。看下面MAT-File Format Options部分。 |
-version 版本
| Save in a format that can be loaded into an earlier version of MATLAB. See the section on Version Compatibility Options, below. 以一种可以下载早期版本的MATLAB格式保存。看下面Version Compatibility Options部分。 matabc
|
save filename content options stores only those variables specified by content in file filename, also applying the specified options. If filename is not specified, MATLAB stores the data in a file called matlab.mat. matlab
文件内容选择保存仅仅保存那些在文件名中被详细说明的变量,同时也根据已说明的选择规则。如果文件名没有被详细说明,那么MATLAB将数据保存在一个名叫matlab.mat的文件中。
save('filename', 'var1', 'var2', ...) is the function form of the syntax.
save('filename', 'var1', 'var2', ...) 这种形式是函数格式。
The following table lists the valid MAT-file format options.
以下的表格陈列了有效的MAT-file 格式选择规则。 matlab
MAT-file format Options MAT-file 格式选择 | How Data Is Stored 数据被存储的方式 |
-ascii | Save data in 8-digit ASCII format. 以8位元ASCII 格式保存数据
|
-ascii -tabs | Save data in 8-digit ASCII format delimited with tabs. 以tabs为界将数据按8位元ASCII 格式保存
|
-ascii -double | Save data in 16-digit ASCII format. 以16位元ASCII 格式保存数据 |
-ascii -double -tabs | Save data in 16-digit ASCII format delimited with tabs. 以tabs为界将数据按16位元ASCII 格式保存 |
-mat | Binary MAT-file form (default).
|
Version Compatibility Options
The following table lists version compatibility options. These options enable you to save your workspace data to a MAT-file that can then be loaded into an earlier version of MATLAB software. The resulting MAT-file supports only those data items and features that were available in this earlier version of MATLAB. (See the second table below for what is supported in each version.)
下面的表格陈列的是不同版本兼容性的选择规则。这个选项能够让你将工作空间中的数据保存到一个MAT-file 的文件中,而这个文件能够被更早MATLAB软件下载。那么这样子以来,MAT-file文件就只能支持对早期MATLAB版本有效的数据项。(下面第二个表格说明了在各个版本中所被支持的数据项) matlab
version Option 版本选项 | Use When Running ...
所用版本
| To Save a MAT-File That You Can Load In ...
为了保存一个MAT-File文件用户所需下载的版本 |
-v7.3 | Version 7.3 or later 7.3版本或之后的版本
| Version 7.3 or later
7.3版本或之后的版本 |
-v7 | Version 7.3 or later 7.3版本或之后的版本
| Versions 7.0 through 7.2 (or later) 7.0到7.2版本或之后的版本 |
-v6 | Version 7 or later 7.0版本或之后的版本
| Versions 5 and 6 (or later) 5.0,6.0版本或之后的版本 |
-v4 | Version 5 or later 5.0版本或之后的版本
| Versions 1 through 4 (or later) 1.0到4.0版本或之后的版本 |
The default version option is the value specified in the Preferences dialog box. Select File → Preferences in the Command Window, click General, and then MAT-Files to view or change the default.
在参数选择对话框中,系统默认版本的选择是非常有价值的。在命令窗口中选择文件,然后选择参数选择,再单击General,那么MAT-Files 文件就可以看到了,同时系统默认值也可以更改了。
The next table shows what data items and features are supported in different versions of MATLAB. You can use this information to determine which of the version compatibility options shown above to use. matabc
以下的表格显示了在MATLAB的各个版本中,哪些数据项是被支持的。用户就可以根据这个信息来确定使用哪一个的兼容性版本。
MATLAB Versions MATLAB版本 | Data Items or Features Supported 所支持的数据项或特征
|
4 and earlier 4.0版本或更早的版本 | Support for 2D double, character, and sparse 支持二维双精度,字符和矩阵
|
5 and 6 5.0和6.0版本 | Version 4 capability plus support for ND arrays, structs, and cells 4.0版本容量附加额支持ND数组,结构和单元格
|
7.0 through 7.2 7.0到7.2版本
| Version 6 capability plus support for data compression and Unicode character encoding 6.0版本容量附加额支持数据压缩和Unicode 型编码
|
7.3 and later 7.3及之后的版本 | Version 7.2 capability plus support for data items greater than or equal to 2GB 7.2版本容量附加额支持2GB大小或更大的数据项
|
Remarks编辑本段回目录
When using the -regexp switch, save considers all variables in the argument list, with the exception of the optional filename and structure name variables, to be regular expressions. The filename, if specified, is always the first argument in the argument list, provided that this argument is a variable name. The structure name, if specified, is always the first argument following the -struct keyword, provided that the argument list includes that keyword.
当使用the -regexp 按钮的时候,save认为除了可选择的文件名变量和结构名变量之外,所有在变元表里的变量都应该是正则表达式。如果详细说明,一般情况下文件名都是变元表里的第一个内容提要,说明这个内容是一个变量名。而结构名则一般是the-struct关键字接下来的第一个内容提要,说明这个变元表包括了那个关键字。
When working on 64-bit platforms, you can have data items in your workspace that occupy more than 2 GB. To save data of this size, you must use the HDF5-based version of the MATLAB MAT-file. Use the –v7.3 option to do this:
当在64比特的平台上工作时,用户可以在自己的工作空间拥有一个大于2GB的数据项。为了保存这样大容量的数据,用户必须使用MATLAB MAT-file HDF5-based版本。使用 v7.3选项应按如下格式操作:
save -v7.3 myfile v1 v2
If you are running MATLAB on a 64-bit computer system and you attempt to save a variable that is too large for a version 7 (or earlier) MAT-file, that is, you save without using the -v7.3 option, MATLAB skips that variable during the save operation and issues a warning message to that effect.
如果用户在一个64比特的计算机系统中运行MATLAB,并且想要保存一个变量,而这个对于7.0版本(或更早的版本)的MAT-file而言容量太大,也就是用户在保存的时候并没有使用v7.3选项,MATLAB就会在保存操作过程中跳过该变量并且发出一个警告信息。
If you are running MATLAB on a 32-bit computer system and attempt to load a variable from a -v7.3 MAT-file that is too large to fit in 32–bit address space, MATLAB skips that variable and issues a warning message to that effect.
如果用户正在一台32比特的计算机系统上运行MATLAB并且想要从v7.3版本的MAT-file文件中下载一个变量,而这个变量对于32比特的地址空间而言又太大了,那么MATLAB就会跳过那个变量同时发出一个警告信息。 matabc
MAT-files saved with compression and Unicode encoding cannot be loaded into versions of MATLAB prior to MATLAB Version 7.0. If you save data to a MAT-file that you intend to load using MATLAB Version 6 or earlier, you must specify the -v6 option when saving. This disables compression and Unicode encoding for that particular save operation.
MAT-files文件保存的压缩和Unicode编码并不能被MATLAB7.0和之前的版本所下载。如果用户试图通过MATLAB6.0或更早的版本中将数据保存到MAT-files文件中,那么就必须在保存的时候说明v6选项。而对于这样一个特殊的保存操作,计算机是无法进行压缩和Unicode编码的。 matabc
If you want to save to a file that you can then load into a Version 4 MATLAB session, you must use the -v4 option when saving. When you use this option, variables that are incompatible with MATLAB Version 4 are not saved to the MAT-file. For example, ND arrays, structs, cells, etc. cannot be saved to a MATLAB Version 4 MAT-file. Also, variables with names that are longer than 19 characters cannot be saved to a MATLAB Version 4 MAT-file.
如果用户想保存一个可以下载到MATLAB4.0版本中的文件,那么就必须在保存的时候使用v4选项。当使用这个选项的时候,与MATLAB4.0版本不相容的变量就不会被保存到MAT-file文件中。比如,ND数组,结构和单元格等等就不可能被保存到MATLAB4.0版本的MAT-file文件中。同样,长度大于19字符的变量名字也不可能被保存到MATLAB4.0版本的MAT-file文件中。
For information on any of the following topics related to saving to MAT-files, see Exporting Data to MAT-Files in the MATLAB Programming Fundamentals documentation:
以下有关保存到MAT-file文件的信息,请查看MATLAB 程序编制基本文件中的Exporting Data to MAT-Files :
* Appending variables to an existing MAT-file matlab
*在现存的MAT-file文件中附加变量
* Compressing data in the MAT-file
*在MAT-file文件中压缩数据
* Saving in ASCII format
*以ASCII 格式保存 matabc
* Saving in MATLAB Version 4 format
*MATLAB4.0版本格式保存
*Saving with Unicode character encoding matlab
*以Unicode字符编码保存
* Data storage requirements
*数据存储要求
* Saving from external programs
*从外部程序保存
For information on saving figures, see the documentation for hgsave and saveas. For information on exporting figures to other graphics formats, see the documentation for print.
关于保存图形的信息,请查看hgsave和saveas。关于以其他格式输出图形的信息,请查看print。
matabc
Examples编辑本段回目录
Save all variables from the workspace in binary MAT-file test.mat:
从工作空间中将所有的变量保存到二进制MAT-file文件中,并以test.mat命名,可表达为: matabc
save test.mat
Save variables p and q in binary MAT-file test.mat.
将变量p和q保存到二进制MAT-file文件中的。 matabc
In this example, the file name is stored in a variable, savefile. You must call save using the function syntax of the command if you intend to reference the file name through a variable.
在这个例子中,文件名被保存在一个名为savefile的变量中。如果用户视图通过一个变量引用文件名,那么就必须在保存的时候使用命令函数语法。
savefile = 'test.mat';
p = rand(1, 10);
q = ones(10);
save(savefile, 'p', 'q')
Save the values of variables vol and temp in ASCII format to a file named june10: matlab
将一个名叫june10文件夹中的变量以ASCII格式对vol和temp进行保存,表达如下:
save('d:\mymfiles\june10','vol','temp','-ASCII')
matabc
Save the fields of structure s1 as individual variables rather than as an entire structure.
将结构体s1作为一个个体变量进行保存而不是整体变量。
s1.a = 12.7; s1.b = {'abc', [4 5; 6 7]}; s1.c = 'Hello!';
save newstruct.mat -struct s1;
clear
Check what was saved to newstruct.mat:
whos -file newstruct.mat
Name Size Bytes Class
a 1x1 8 double array
b 1x2 158 cell array
c 1x6 12 char array
Grand total is 16 elements using 178 bytes
Read only the b field into the MATLAB workspace.
str = load('newstruct.mat', 'b')
str =
b: {'abc' [2x2 double]}
Using regular expressions, save in MAT-file mydata.mat those variables with names that begin with Mon, Tue, or Wed:
通过使用正则表达式,在MAT-file mydata.mat文件中将以Mon, Tue,或者 Wed开头命名的变量进行保存,表达式如下: matabc
save('mydata', '-regexp', '^Mon|^Tue|^Wed');
Here is another way of doing the same thing. In this case, there are three separate expression arguments:
下面是另一种表达方式。在这个例子中,有三个独立的表达式参数,表达如下:
save('mydata', '-regexp', '^Mon', '^Tue', '^Wed');
Save a 3000-by-3000 matrix uncompressed to file c1.mat, and compressed to file c2.mat. The compressed file uses about one quarter the disk space required to store the uncompressed data:
将一个3000*3000的无压缩矩阵保存到一个名为c1.mat的文件夹中,并且压缩到名为c2.mat的文件中。被压缩了的文件将使用近四分之一的磁盘空间,而这些空间就是用来存储还未被压缩的数据,表达如下:
x = ones(3000);
y = uint32(rand(3000) * 100);
save -v6 c1 x y % Save without compression
save -v7 c2 x y % Save with compression
d1 = dir('c1.mat');
d2 = dir('c2.mat');
d1.bytes
ans =
45000240 % Size of the uncompressed data in bytes.
d2.bytes
ans =
11985283 % Size of the compressed data in bytes.
d2.bytes/d1.bytes
ans =
0.2663 % Ratio of compressed to uncompressed
See Also编辑本段回目录
功能简介编辑本段回目录
保存workspace中的变量到文件中。 matlab
版本支持编辑本段回目录
使用方法编辑本段回目录
save(filename)
save(filename, variables)
save(filename, '-struct', structName, fieldNames)
save(filename, ..., '-append')
save(filename, ..., format)
save(filename, ..., version)
save filename ... matlab
save(filename)
保存matlab目前工作空间中的变量到matlab mat文件中去,mat文件名字为filename所定义。
save(filename, variables)
保存matlab目前工作空间中名字为variables所定义的变量到matlab mat文件中去,mat文件名字为filename所定义。 matlab
save(filename, '-struct', structName, fieldNames)
保存指定structure的field名字作为单个变量到matlab mat文件中去,mat文件名字为filename所定义。 matlab
save(filename, ..., '-append')
增加新的变量到已存在的matlab mat文件中去,mat文件名字为filename所定义。
save(filename, ..., format) matabc
保存为不同的格式,格式可选择为mat或者ascii。 matlab
matlab
应用举例编辑本段回目录
savefile = 'pqfile.mat';
p = rand(1, 10);
q = ones(10);
save(savefile, 'p', 'q')