求指点MATLAB的save函数
如下,从第四行开始是什么意思,菜鸟太菜。。>>A=ones(2,3);>>B=[1,2,3];>>C=magic(5);>>savemydateA>>save('myda...
如下,从第四行开始是什么意思,菜鸟太菜。。
>> A=ones(2,3);
>> B=[1,2,3];
>> C=magic(5);
>> save mydate A
>> save('mydate','B','-append');
>> save('mydate','C','-ascii') 展开
>> A=ones(2,3);
>> B=[1,2,3];
>> C=magic(5);
>> save mydate A
>> save('mydate','B','-append');
>> save('mydate','C','-ascii') 展开
3个回答
展开全部
>> save mydate A
把变量A存为 mydate.mat 文件
>> save('mydate','B','-append');
把变量B添加到 mydate.mat 文件中,现在 mydate.mat有两个变量A和B
>> save('mydate','C','-ascii')
把变量C以ASCII格式存为mydate 文件
把变量A存为 mydate.mat 文件
>> save('mydate','B','-append');
把变量B添加到 mydate.mat 文件中,现在 mydate.mat有两个变量A和B
>> save('mydate','C','-ascii')
把变量C以ASCII格式存为mydate 文件
追问
最后一行写漏了,应该是
>> A=ones(2,3);
>> B=[1,2,3];
>> C=magic(5);
>> save mydate A
>> save('mydate','B','-append');
>> save('mydate','C','-append','-ascii')
那最后一行表示的是什么意思?
是把变量C以ASCII形式存在mydate.mat 文件中吗?
追答
不是,是ASCII码的文件,不在.mat里面
matlab里试了一下应该是这样
展开全部
MATLAB储存变数的基本命令是save,在不加任何选项(Options)时,save会将变数以二进制(Binary)的方式储存至副档名为mat的档案,如下述:
save:将工作空间的所有变数储存到名为matlab.mat的二进制档案。
save filename:将工作空间的所有变数储存到名为filename.mat的二进制档案。 save filename x y z :将变数x、y、z储存到名为filename.mat的二进制档案。
以下为使用save命令的一个简例:
who % 列出工作空间的变数
Your variables are:
B h j y
ans i x z
save test B y % 将变数B与y储存至test.mat
dir % 列出现在目录中的档案
. 2plotxy.doc fact.m simulink.doc test.m ~$1basic.doc
.. 3plotxyz.doc first.doc temp.doc test.mat
1basic.doc book.dot go.m template.doc testfile.dat
delete test.mat % 删除test.mat
以二进制的方式储存变数,通常档案会比较小,而且在载入时速度较快,但是就无法用普通的文书软体(例如pe2或记事本)看到档案内容。若想看到档案内容,则必须加上-ascii选项,详见下述:
save filename x -ascii:将变数x以八位数存到名为filename的ASCII档案。
Save filename x -ascii -double:将变数x以十六位数存到名为filename的ASCII档案。
另一个选项是-tab,可将同一列相邻的数目以定位键(Tab)隔开。
小提示:二进制和ASCII档案的比较 在save命令使用-ascii选项後,会有下列现象:save命令就不会在档案名称後加上mat的副档名。
因此以副档名mat结尾的档案通常是MATLAB的二进位资料档。
若非有特殊需要,我们应该尽量以二进制方式储存资料。
save:将工作空间的所有变数储存到名为matlab.mat的二进制档案。
save filename:将工作空间的所有变数储存到名为filename.mat的二进制档案。 save filename x y z :将变数x、y、z储存到名为filename.mat的二进制档案。
以下为使用save命令的一个简例:
who % 列出工作空间的变数
Your variables are:
B h j y
ans i x z
save test B y % 将变数B与y储存至test.mat
dir % 列出现在目录中的档案
. 2plotxy.doc fact.m simulink.doc test.m ~$1basic.doc
.. 3plotxyz.doc first.doc temp.doc test.mat
1basic.doc book.dot go.m template.doc testfile.dat
delete test.mat % 删除test.mat
以二进制的方式储存变数,通常档案会比较小,而且在载入时速度较快,但是就无法用普通的文书软体(例如pe2或记事本)看到档案内容。若想看到档案内容,则必须加上-ascii选项,详见下述:
save filename x -ascii:将变数x以八位数存到名为filename的ASCII档案。
Save filename x -ascii -double:将变数x以十六位数存到名为filename的ASCII档案。
另一个选项是-tab,可将同一列相邻的数目以定位键(Tab)隔开。
小提示:二进制和ASCII档案的比较 在save命令使用-ascii选项後,会有下列现象:save命令就不会在档案名称後加上mat的副档名。
因此以副档名mat结尾的档案通常是MATLAB的二进位资料档。
若非有特殊需要,我们应该尽量以二进制方式储存资料。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-06-03
展开全部
save函数
保存当前工作空间的所有变量到文件名制定的文件中,此文件后缀名通常为mat。如果不指定文件名变量,则会默认保存到matlab.mat这个文件中的一种运算符法。
函数编程:
SAVE Save workspace variables to disk.
SAVE FILENAME saves all workspace variables to the binary "MAT-file"
named FILENAME.mat. The data may be retrieved with LOAD. If FILENAME
has no extension, .mat is assumed.
SAVE, by itself, creates the binary "MAT-file" named 'matlab.mat'.
SAVE FILENAME X saves only X.
SAVE FILENAME X Y Z saves X, Y, and Z. The wildcard '*' can be used to
save only those variables that match a pattern.
SAVE FILENAME -REGEXP PAT1 PAT2 can be used to save all variables
matching the specified patterns using regular expressions. For more
information on using regular expressions, type "doc regexp" at the
command prompt.
SAVE FILENAME -STRUCT S saves the fields of the scalar structure S as
individual variables within the file FILENAME.
SAVE FILENAME -STRUCT S X Y Z saves the fields S.X, S.Y and S.Z to
FILENAME as individual variables X, Y and Z.
SAVE FILENAME ... -APPEND adds the variables to an existing file
(MAT-file only).
Format Options:
SAVE ... -ASCII uses 8-digit ASCII form instead of binary regardless
of file extension.
SAVE ... -ASCII -DOUBLE uses 16-digit ASCII form.
SAVE ... -ASCII -TABS delimits with tabs.
SAVE ... -ASCII -DOUBLE -TABS 16-digit, tab delimited.
SAVE ... -MAT saves in MAT format regardless of extension.
Version Compatibility Options:
The following options enable you to save your workspace data to a
MAT-file that can then be loaded into an earlier version of MATLAB.
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.)
Command Option | Saves a MAT-File That You Can Load In
主要公式:
-----------------+----------------------------------------------
SAVE ... -V7.3 | Version 7.3 or later
-----------------+----------------------------------------------
SAVE ... -V7 | Versions 7.0 through 7.2 (or later)
-----------------+----------------------------------------------
SAVE ... -V6 | Versions 5 and 6 (or later)
-----------------+----------------------------------------------
SAVE ... -V4 | Versions 1 through 4 (or later)
To make one of these options the default for all of your MATLAB
sessions, use the Preferences dialog box. In the MATLAB File menu,
select Preferences. Then, in the Preferences dialog box, click
General and then MAT-Files.
MATLAB Versions | Data Items or Features Supported
-----------------+----------------------------------------------
4 and earlier | Support for 2D double, character, and sparse
| arrays
-----------------+----------------------------------------------
5 and 6 | Version 4 capability plus support for
| ND arrays, structs, and cells
-----------------+----------------------------------------------
7.0 through 7.2 | Version 6 capability plus support for data
| compression and Unicode character encoding
-----------------+----------------------------------------------
7.3 and later | Version 7.2 capability plus support for
| data items greater than or equal to 2GB
Examples for pattern matching:
save fname a* % Save variables starting with "a"
save fname -regexp \d % Save variables containing any digits
Examples for specifying filename and variables:
save mydata.mat v1 % Use with literal filename
save 'my data file.mat' v1 % Use when filename has spaces
save(savefile, 'v1') % Use when filename is stored in a variable
保存当前工作空间的所有变量到文件名制定的文件中,此文件后缀名通常为mat。如果不指定文件名变量,则会默认保存到matlab.mat这个文件中的一种运算符法。
函数编程:
SAVE Save workspace variables to disk.
SAVE FILENAME saves all workspace variables to the binary "MAT-file"
named FILENAME.mat. The data may be retrieved with LOAD. If FILENAME
has no extension, .mat is assumed.
SAVE, by itself, creates the binary "MAT-file" named 'matlab.mat'.
SAVE FILENAME X saves only X.
SAVE FILENAME X Y Z saves X, Y, and Z. The wildcard '*' can be used to
save only those variables that match a pattern.
SAVE FILENAME -REGEXP PAT1 PAT2 can be used to save all variables
matching the specified patterns using regular expressions. For more
information on using regular expressions, type "doc regexp" at the
command prompt.
SAVE FILENAME -STRUCT S saves the fields of the scalar structure S as
individual variables within the file FILENAME.
SAVE FILENAME -STRUCT S X Y Z saves the fields S.X, S.Y and S.Z to
FILENAME as individual variables X, Y and Z.
SAVE FILENAME ... -APPEND adds the variables to an existing file
(MAT-file only).
Format Options:
SAVE ... -ASCII uses 8-digit ASCII form instead of binary regardless
of file extension.
SAVE ... -ASCII -DOUBLE uses 16-digit ASCII form.
SAVE ... -ASCII -TABS delimits with tabs.
SAVE ... -ASCII -DOUBLE -TABS 16-digit, tab delimited.
SAVE ... -MAT saves in MAT format regardless of extension.
Version Compatibility Options:
The following options enable you to save your workspace data to a
MAT-file that can then be loaded into an earlier version of MATLAB.
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.)
Command Option | Saves a MAT-File That You Can Load In
主要公式:
-----------------+----------------------------------------------
SAVE ... -V7.3 | Version 7.3 or later
-----------------+----------------------------------------------
SAVE ... -V7 | Versions 7.0 through 7.2 (or later)
-----------------+----------------------------------------------
SAVE ... -V6 | Versions 5 and 6 (or later)
-----------------+----------------------------------------------
SAVE ... -V4 | Versions 1 through 4 (or later)
To make one of these options the default for all of your MATLAB
sessions, use the Preferences dialog box. In the MATLAB File menu,
select Preferences. Then, in the Preferences dialog box, click
General and then MAT-Files.
MATLAB Versions | Data Items or Features Supported
-----------------+----------------------------------------------
4 and earlier | Support for 2D double, character, and sparse
| arrays
-----------------+----------------------------------------------
5 and 6 | Version 4 capability plus support for
| ND arrays, structs, and cells
-----------------+----------------------------------------------
7.0 through 7.2 | Version 6 capability plus support for data
| compression and Unicode character encoding
-----------------+----------------------------------------------
7.3 and later | Version 7.2 capability plus support for
| data items greater than or equal to 2GB
Examples for pattern matching:
save fname a* % Save variables starting with "a"
save fname -regexp \d % Save variables containing any digits
Examples for specifying filename and variables:
save mydata.mat v1 % Use with literal filename
save 'my data file.mat' v1 % Use when filename has spaces
save(savefile, 'v1') % Use when filename is stored in a variable
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询