如何在MATLAB中获取文件的长度? [英] How to get the length of a file in MATLAB?

查看:2654
本文介绍了如何在MATLAB中获取文件的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以计算出.dat文件的长度(以行为单位),而无需将该文件加载到工作区中?

Is there any way to figure out the length of a .dat file (in terms of rows) without loading the file into the workspace?

推荐答案

行计数器-每行仅加载一个字符:

Row Counter -- only loads one character per row:

Nrows = numel(textread('mydata.txt','%1c%*[^\n]'))

或文件长度(matlab):

or file length (Matlab):

datfileh = fopen(fullfile(path, filename));
fseek(datfileh, 0,'eof');
filelength = ftell(datfileh);
fclose(datfileh);

这篇关于如何在MATLAB中获取文件的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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