How do you get the size of a file in MATLAB?

前端 未结 7 1828
耶瑟儿~
耶瑟儿~ 2020-12-09 07:36

What is the best way to figure out the size of a file using MATLAB? The first thought that comes to mind is size(fread(fid)).

相关标签:
7条回答
  • 2020-12-09 08:35

    The question seems to indicate that fopen/fread/.. is used. In this case, why not seeking to the end of the file and reading the position?

    Example:

    function file_length = get_file_length(fid)
    % extracts file length in bytes from a file opened by fopen
    % fid is file handle returned from fopen
    
    % store current seek
    current_seek = ftell(fid);
    % move to end
    fseek(fid, 0, 1);
    % read end position
    file_length = ftell(fid);
    % move to previous position
    fseek(fid, current_seek, -1);
    
    end
    

    Matlab could have provided a shortcut..

    More on ftell can be found here.

    0 讨论(0)
提交回复
热议问题