MATLAB數(shù)據(jù)導(dǎo)入與導(dǎo)出_第1頁
MATLAB數(shù)據(jù)導(dǎo)入與導(dǎo)出_第2頁
MATLAB數(shù)據(jù)導(dǎo)入與導(dǎo)出_第3頁
MATLAB數(shù)據(jù)導(dǎo)入與導(dǎo)出_第4頁
MATLAB數(shù)據(jù)導(dǎo)入與導(dǎo)出_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、MATLAB的數(shù)據(jù)導(dǎo)入與導(dǎo)出1MATLAB的數(shù)據(jù)導(dǎo)入數(shù)據(jù)的直接輸入 A=1 2 3 4 5 6;M文件中生成利用fopen,fread,和MATLAB輸入輸出函數(shù)。從ASCII文件中導(dǎo)入 利用load命令2LOAD 接受絕對或相對路徑輸入。如果文件的擴(kuò)展名不是.mat,則系統(tǒng)把文件當(dāng)作ASCII碼文件進(jìn)行處理。單獨(dú)使用時(shí),默認(rèn)輸入的命令matlab.mat。如果找不到這個(gè)文件,則會(huì)報(bào)錯(cuò)。LOAD X loads only X.LOAD X Y Z . loads just the specified variables. The wildcard * loads variables that

2、match a pattern (MAT-).如果文件是mat文件,所需變量將在工作空間產(chǎn)生,否則,會(huì)產(chǎn)生一個(gè)雙精度矩陣,矩陣名為文件名。 S = LOAD(.) returns the contents of in variable S. If is a MAT file, S is a struct containing fields matching the variables retrieved. If is an ASCII file, S is a double precision array.3舉例load fname a* % Load variables starting w

3、ith a load fname -regexp bd3$ % Load variables starting with b and % followed by 3 digits load fname -regexp d % Load variables containing any digits4利用特定文件讀取函數(shù) dlmreadwk1readtextscantextread創(chuàng)建mex文件讀取文件創(chuàng)建其他程序文件讀取5MATLAB的數(shù)據(jù)導(dǎo)出diarysave ascii以特定格式寫入文件利用特定文件寫入程序dlmwrite作為mat文件輸出數(shù)據(jù)6MATLAB的文件操作 UIGETFILE

4、對話框打開文件方式. , PATHNAME, FILTERINDEX = UIGET, TITLE)顯示一個(gè)需要用戶完成的對話框,返回文件名,文件路徑,和是否打開成功,如果打開成功,返回成功標(biāo)志,否則會(huì)出現(xiàn)一錯(cuò)誤信息,用戶可以打開另一文件,或取消。 , pathname, filterindex = uigetfile(*.m, Pick an M-file); 7MATLAB的文件操作UIPUTFILE 對話框打開文件方式. , PATHNAME, FILTERINDEX = UIPUT, TITLE)顯示一個(gè)需要用戶完成的對話框,返回文件名,文件路徑,和是否打開成功,如果打開成功,返回成功

5、標(biāo)志,否則會(huì)出現(xiàn)一錯(cuò)誤信息,用戶可以打開另一文件,或取消。 , pathname = uiputfile(matlab.mat, Save Workspace as); 8MATLAB的文件操作 FOPEN 打開文件 可以是一個(gè)相對路徑,如果文件不在當(dāng)前目錄,系統(tǒng)將會(huì)在其他路徑進(jìn)行搜索。FID = FOPEN()FID 稱為文件標(biāo)識(shí)符,如果錯(cuò)誤,返回-1 9MATLAB的文件操作 r read w write (create if necessary) a append (create if necessary) r+ read and write (do not create) w+ tru

6、ncate or create for read and write a+ read and append (create if necessary) W write without automatic flushing A append without automatic flushing10MATLAB的文件操作Two are automatically available and need not be opened. They are FID=1 (standard output) and FID=2 (standard error).FID, MESSAGE = FOPEN() re

7、turns a system dependent error message if the open is not successful.11MATLAB的文件操作FCLOSE Close file. ST = FCLOSE(FID) closes the FID, which is an integer obtained from an earlier FOPEN. FCLOSE returns 0 if successful and -1 if not. ST = FCLOSE(a) closes all open files, except 0, 1 and 2.12MATLAB的文件操

8、作 FGETS Read line from file, keep newline character. TLINE = FGETS(FID) returns the next line of a with FID as a MATLAB string. The line terminator is included. Use FGETL to get the next line WITHOUT the line terminator. If just an end-of- encountered then -1 is returned.13MATLAB的文件操作FPRINTF Write f

9、ormatted data to file. COUNT = FPRINTF(FID,FORMAT,A,.) formats the data in the real part of array A (and in any additional array arguments), under control of the specified FORMAT string, and writes it to the file associated with FID. COUNT is the number of bytes successfully written. FID is an integer obtained from FOPEN. It can also be 1 for standard output (the screen) or 2 for standard error. If FID is omitted, output goes to

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論