English 中文(简体)
如何在书目中注明档案的终结
原标题:How to indicate to the end of file in matlab

我有一份以双亲格式保存的固定档案,即希望按具体顺序阅读,直到该档案结束,因此,我们需要一种条件,即表明档案结束的条件是什么?

顺便说一句,我不想把整个档案装上空档,而是想到当时需要读到的位置,直到档案结束。

问题回答

MATLAB s fread function (and, actual, the other file IO function) will autotecating the end of a binary file; there s no need for a special end offile signer.

http://www.mathwork.co.uk/help/techdoc/ref/fread.html>rel=“nofollow”>。

rel=“nofollow> MATLAB IO文件

您可使用feof测试文档的终结。 例如,在以下时间读一个档案:

fid = fopen( bench.dat );

k = 0;
while ~feof(fid)
    curr = fscanf(fid, %c ,1);
    if ~isempty(curr)
       k = k+1;
       benchstr(k) = curr;
    end
end

fclose(fid);

You can pass Inf for the size argument when using the FREAD function (will read until end of file). Here is an example:

%# first lets create a simple binary file
fid = fopen( file.bin ,  wb );
fwrite(fid,  hello world ,  char*1 );
fclose(fid);

%# now open binary file, seek to some position, and read bytes till EOF
fid = fopen( file.bin ,  rb );
fseek(fid, 6,  bof );                %# go to the 7th byte
B = fread(fid, Inf,  uint8=>char );  %# read bytes until end-of-file (as chars)
fclose(fid);

disp(B)




相关问题
Is There Any Way Without File.ReadAllText?

As I love to develop file I/O applications and my new development platform is Windows Mobile. Is there any way to read all the file, without using File.ReadAllText? Because Windows Mobile doesn t ...

File paths in Java (Linux)

I have created a Java application that loads some configurations from a file conf.properties which is placed in src/ folder. When I run this application on Windows, it works perfectly. However when I ...

How do I create a string using a loop variable in MATLAB?

I have a loop like this: for i=1:no %some calculations fid = fopen( c:\out.txt , wt ); %write something to the file fclose(fid); end I want data to be written to different files like ...

热门标签