3 回答

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊
MATLAB儲(chǔ)存變數(shù)的基本命令是save,在不加任何選項(xiàng)(Options)時(shí),save會(huì)將變數(shù)以二進(jìn)制(Binary)的方式儲(chǔ)存至副檔名為mat的檔案,如下述:
save:將工作空間的所有變數(shù)儲(chǔ)存到名為matlab.mat的二進(jìn)制檔案。
save filename:將工作空間的所有變數(shù)儲(chǔ)存到名為filename.mat的二進(jìn)制檔案。 save filename x y z :將變數(shù)x、y、z儲(chǔ)存到名為filename.mat的二進(jìn)制檔案。
以下為使用save命令的一個(gè)簡(jiǎn)例:
who % 列出工作空間的變數(shù)
Your variables are:
B h j y
ans i x z
save test B y % 將變數(shù)B與y儲(chǔ)存至test.mat
dir % 列出現(xiàn)在目錄中的檔案
. 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
以二進(jìn)制的方式儲(chǔ)存變數(shù),通常檔案會(huì)比較小,而且在載入時(shí)速度較快,但是就無(wú)法用普通的文書(shū)軟體(例如pe2或記事本)看到檔案內(nèi)容。若想看到檔案內(nèi)容,則必須加上-ascii選項(xiàng),詳見(jiàn)下述:
save filename x -ascii:將變數(shù)x以八位數(shù)存到名為filename的ASCII檔案。
Save filename x -ascii -double:將變數(shù)x以十六位數(shù)存到名為filename的ASCII檔案。
另一個(gè)選項(xiàng)是-tab,可將同一列相鄰的數(shù)目以定位鍵(Tab)隔開(kāi)。
小提示:二進(jìn)制和ASCII檔案的比較 在save命令使用-ascii選項(xiàng)後,會(huì)有下列現(xiàn)象:save命令就不會(huì)在檔案名稱(chēng)後加上mat的副檔名。
因此以副檔名mat結(jié)尾的檔案通常是MATLAB的二進(jìn)位資料檔。
若非有特殊需要,我們應(yīng)該盡量以二進(jìn)制方式儲(chǔ)存資料。

TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊
>> save mydate A
把變量A存為 mydate.mat 文件
>> save('mydate','B','-append');
把變量B添加到 mydate.mat 文件中,現(xiàn)在 mydate.mat有兩個(gè)變量A和B
>> save('mydate','C','-ascii')
把變量C以ASCII格式存為mydate 文件

TA貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個(gè)贊
save函數(shù)
保存當(dāng)前工作空間的所有變量到文件名制定的文件中,此文件后綴名通常為mat。如果不指定文件名變量,則會(huì)默認(rèn)保存到matlab.mat這個(gè)文件中的一種運(yùn)算符法。
函數(shù)編程:
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
- 3 回答
- 0 關(guān)注
- 1767 瀏覽
添加回答
舉報(bào)