C# 从matlab读取平面文件

C# 从matlab读取平面文件,c#,matlab,file-io,binaryfiles,C#,Matlab,File Io,Binaryfiles,我想通过matlab读取包含二进制数据的平面文件,,, 我该怎么做。。? 数据实际上是双精度的数字,以二进制形式保存在.dat文件中 谢谢使用FileStream打开此文件,然后将其包装到BinaryReader中。它提供了ReadDouble、ReadByte等方法。有很多方法可以实现这一点,我通常使用 如果您的数据很难放入内存,您可以通过多次读取来访问它 sizeToRead = 10000; %# limit size to 10000 values

我想通过matlab读取包含二进制数据的平面文件,,, 我该怎么做。。? 数据实际上是双精度的数字,以二进制形式保存在.dat文件中


谢谢

使用FileStream打开此文件,然后将其包装到BinaryReader中。它提供了ReadDouble、ReadByte等方法。

有很多方法可以实现这一点,我通常使用

如果您的数据很难放入内存,您可以通过多次读取来访问它

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

如果numel(myData)~=sizeToRead keepGoing=0;结束此条件是什么?还有laurent先生,,,如何查找二进制文件中的特定位置,例如,我想将指针(光标)从0(开始)移动到123>>?如果读取数据的数量与您要求的不同,则您位于文件末尾,并退出循环。要查找给定位置,请使用
fseek(fileId,numberOfBytes,'cof')
“double”的大小为8个字节,因此在您的情况下,您需要执行
fseek(fileId,8*123,'cof')
什么是(123)?8是double的大小,但123是什么?还有laurent先生如何获取文件中的当前指针位置:?
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