2011-10-19 73 views
-3

我想讀取包含二進制throght matlab中的數據的平面文件,,, 我該怎麼做..? 的數據實際上是雙號的.dat文件從matlab中讀取平面文件

感謝

回答

1

有許多方法來做到這一點,我通常用fread

fileId = fopen('mybinaryfile.dat','r'); %# open the file for reading 
myData = fread(fileId,Inf,'double'); %# read everything (Inf) in the file as 'double' values 

如果你的數據將很難適合在內存中,您可以使用多個訪問讀取

sizeToRead = 10000;      %# limit size to 10000 values 
fileId = fopen('mybinaryfile.dat','r'); %# open the file for reading 

keepGoing=1;       %# initialize loop 
while(keepGoing) 
    %# read a maximum of 'sizeToRead' values 
    myData = fread(fileId,sizeToRead,'double'); 

    %# ... 
    %# process your data here  
    %# ... 

    %# make the loop stop if end of file is reached or error happened 
    if numel(myData) ~= sizeToRead 
    keepGoing=0; 
    end 
end 
+0

更新了巨大數據文件處理的代碼 –

+0

如果numel(myData)〜= sizeToRead keepGoing = 0;結束 這是什麼情況? – qwe

+0

和先生laurent ,,,如何尋求在二進制文件中的具體位置,例如我想將指針(光標)從0(開始)移動到123 >>>? – qwe

0

打開此文件中使用的FileStream,然後把它包裝成BinaryReader在保存爲二進制文件。它可以讓你喜歡的readDouble,ReadByte等方法