MATLAB中~feof和feof有什么区别? 50

fid=fopen('magic.m','r'); count=0; while ~feof(fid) line=fgetl(fid); if isempty(line)|strncmp(line,'%',1) continue end count=count+1; end disp(sprintf('%d lines',count)); 运行结果是25lines fid=fop... 展开
我有更好的答案
推荐于2017-05-20 13:27:20 最佳答案


while ~feof 表示 若 未读到文件末尾 则 继续 循环
while feof 表示 若 未读到文件末尾 则 终止 循环,运行结果自然为0

这些都是程序设计的基本知识,所以只循环一次就终止了函数feof(fid) 用法:文件指针 fid 到达文件末尾时返回“真”值;否则返回“假”;

~feof 是在 feof 前加了“非”,是逻辑表达式:文件指针到达文件末尾时 该表达式值为“假”;否则为“真”

其他回答

count] = fgets(obj) returns the number of values read to count, including the terminator.
[tline,msg] = fgets(obj) returns a warning message to msg if the read operation was unsuccessful,msg] = fgets(obj)

Description
tline = fgets(obj) reads one line of text from the device connected to the serial port objectDescription
eofstat = feof(fid) returns 1 if the end-of-file indicator for the file fid has been set and 0 otherwise. (See fopen for a complete description of fid.)
The end-of-file indicator is set when there is no more input from the file.

fgets (serial)
Read line of text from device and include terminator
Syntax
tline = fgets(obj)
[tline, use fgetl.
[tline. This returned data includes the terminator with the text line. To exclude the terminator,count] = fgets(obj)
[tline,count, obj, and returns the data to tline,count
QIANGONG120 | 发布于2015-10-19
评论

为您推荐:

×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消