save

save 

标签: 暂无标签

顶[2]  发表评论(0) 编辑词条
目录

[显示全部]

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部分的内容。 
matlab

 -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中增加新的变量。
matabc

 -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', ...) 这种形式是函数格式。


 

MAT-File Format Options

The following table lists the valid MAT-file format options.

以下的表格陈列了有效的MAT-file 格式选择规则。 matlab

MAT-file format Options 
MAT-file 格式选择
 
 How Data Is Stored

数据被存储的方式
matabc

 -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 格式保存数据 
matabc

 -ascii -double -tabs 
 Save data in 16-digit ASCII format delimited with tabs.

以tabs为界将数据按16位元ASCII 格式保存 

 -mat 

 Binary MAT-file form (default).


系统默认的二进制MAT-file 格式


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

版本选项
  matabc

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版本或之后的版本 
matabc

 -v7  Version 7.3 or later

7.3版本或之后的版本

 Versions 7.0 through 7.2 (or later)

7.0到7.2版本或之后的版本
matabc

 -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编辑本段回目录


 

Example 1


Save all variables from the workspace in binary MAT-file test.mat: 
从工作空间中将所有的变量保存到二进制MAT-file文件中,并以test.mat命名,可表达为: matabc


save test.mat 

Example 2


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')

Example 3


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

Example 4


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]} 

Example 5

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'); 

Example 6


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')

相关函数编辑本段回目录

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
北航《精通matlab6.5》 第一章 基础准备及入门 1.1 MATLAB的安装和内容选择 1.2 Desktop操作桌面的启动 1.3 Command Window运行入门 1.4 Command Window操作要旨 1.5 Command History和实录指令diary 1.7 Workspace Browser和Array Editor 1.8 Launch Pad交互界面分类目录窗 1.9 Editor/Debugger和脚本编写初步 1.10 帮助系统 第二章 数值数组及其运算 2.1 引导 2.2 一维数组的创建和寻访 2.3 二维数组的创建 2.4 二维数组元素的标识 2.5 二维数组的子数组寻访和赋值 2.6 执行数组运算的常用函数 2.7 数组运算的矩阵运算 2.8 多项式的表达方式及其操作 2.9 标准数组生成函数和数组操作函数 2.10 数组构作技法综合 2.11 高维数组 2.12 “非数”和“空”数组 2.13 关系操作和逻辑操作 第三章 字符串、元胞和构架数组 3.1 字符串数组 3.2 元胞数组 3.3 构架数组 3.4 关于数据类型的归纳性说明 第四章 数值计算 4.1 引言 4.2 LU分解和恰定方程组的解 4.3 矩阵特征值和矩阵函数 4.4 奇异值分解 4.5 函数的数值导数和切平面 4.6 函数的零点 4.7 函数极值点 4.8 数值积分 4.9 随机数据的统计描述 4.10 多项式拟合和非线性最小二乘 4.11 插值和样条 4.12 样条函数及其应用 4.13 Fourier分析 4.14 常微分方程 4.15 稀疏矩阵 第五章 符号计算 5.1 符号对象和符号表达式 5.2 符号表达式和符号函数的操作 5.3 符号微积分 5.4 符号积分变换 5.5 符号代数方程的求解 5.6 符号微分方程的求解 5.7 利用MAPLE的深层符号计算资源 5.8 可视化数学分析界面 第六章 数据和函数的可视化 6.1 引导 6.2 二维曲线绘图的基本操作 6.3 三维绘图的基本操作 6.4 特殊图形和高维可视化 6.5 三维图形的精细控制 6.6 图像 6.7 图形窗的图形编辑功能 6.8 函数绘图的简捷指令 6.9 图形的打印和输出 第七章 M文件和面向对象编程 7.1 入门 7.2 M文本编辑器 7.3 MATLAB控制流 7.4 脚本文件和函数文件 7.5 变量的检测传递和限权使用函数 7.6 串演算函数 7.7 函数句柄 7.8 创建用户工具箱 7.9 调试和剖析 7.10 面向对象编程 第八章 SIMULINK交互式仿真集成环境 8.1 引导 8.2 模型的创建 8.3 边续系统建模 8.4 子系统的创建、装帧及受控执行 8.5 离散时间系统和混合系统 8.6 SIMULINK的分析工具 8.7 数值计算方面的考虑 8.8 S函数模块 第九章 句柄图形 9.1 句柄图形体系 9.2 图形对象的操作 9.3 对象属性的获取和设置 9.4 为低层指令绘图准备图/轴 9.5 图形窗的色彩资源和光标属性 9.6 轴对象 9.7 句柄图形应用专题 第十章 图形用户界面GUI制作 10.1 入门 10.2 图形用户界面的设计原则和一般步骤 10.3 界面菜单 uimenu) 10.4 用户控件 uicontrol) 10.5 由M函数文件产生用户菜单和控件 10.6 图形用户界面设计工具 第十一章 MATLAB编译器 11.1 编译器概述 11.2 编译器的安装和配置 11.3 MATLAB编译器使用入门 11.4 编译指令mcc简介 11.5 编译文件的性能优化 11.6 创建独立的外部应用程序 第十二章 应用程序接口API 12.1 C语言MEX文件的编写 12.2 MAT数据文件的应用 12.3 MATLAB引擎技术的应用 12.4 MATLAB中ActiveX技术的应用 12.5 MATLAB中DDE技术的应用 第十三章 Notebook 13.1 Notebook的安装 13.2 Notebook的启动 13.3 M-book模板的使用 13.4 科技演讲稿的制作 附录A:索引 附录B:光盘使用说明 参考文献

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值