2011-10-19 72 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等方法