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

2024-12-26 06:52:42
推荐回答(2个)
回答1:

函数feof(fid) 用法:文件指针 fid 到达文件末尾时返回“真”值;否则返回“假”;

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

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

这些都是程序设计的基本知识,你仔细想下就会明白的。

回答2:

Description
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,count] = fgets(obj)
[tline,count,msg] = fgets(obj)

Description
tline = fgets(obj) reads one line of text from the device connected to the serial port object, obj, and returns the data to tline. This returned data includes the terminator with the text line. To exclude the terminator, use fgetl.
[tline,count] = fgets(obj) returns the number of values read to count, including the terminator.
[tline,count,msg] = fgets(obj) returns a warning message to msg if the read operation was unsuccessful.