matlab quickie:测试文本文件是否为空 [英] matlab quickie: test if text file is empty

查看:120
本文介绍了matlab quickie:测试文本文件是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的问题:我正在matlab 7.x中打开一个文件,并且在读取它之前我想测试它是否为空。什么是这样做的最好方法?

/问题/ 849739 /如何得到大小的文件在MATLAB中>上一个问题,我会做以下:/ b>

  s = dir('c:\somefile.txt'); 
如果s.bytes == 0
%空文件
else
%打开文件并读取它
end;

我假设你的意思是文件中没有包括换行符。如果是空的,则表示只有新行字符,那么您应该继续解决。


Simple question: I am opening a file in matlab 7.x, and I want to test if it is empty before reading it. What's the best way to do this?

解决方案

Taking some knowledge from this previous question, I would do the following

s = dir('c:\somefile.txt');
if s.bytes == 0
    % empty file
else
    % open the file and read it
end;

I assumed by empty that you meant that there is really nothing in the file including new line characters. If by empty you mean only new line characters, then you should go ahead with your solution.

这篇关于matlab quickie:测试文本文件是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆