MATLAB:尽管有权限,但无效的文件标识符

时间:2018-07-10 10:53:29

标签: matlab

我有以下代码:

%% Methods
        function obj = loadDataGroundTruth(obj)

            dataFile = [obj.Configuration.dir.datafiles,'.csv'] ;

            % Open the data file
            fid = fopen(dataFile,'r+'); %# open csv file for reading

            % Scan data file until get to the segments part
            bIdFound = false ;
            while ((~feof(fid)) & (~bIdFound))
                line     = fgets(fid); %# read line by line
                stringId = sscanf(line,'%s'); %# sscanf can read only numeric data :(

                % Stop when we reach the trajectories section
                if strcmp(stringId, 'Segments')
                    bIdFound = true ;
                end
            end

            % Exit if there is not trajectories section in the file
            if (~bIdFound)
                % Close file descriptor
                fclose(fid);

                error('This data file does not contain motion information') ;
            end

应该可以引导.csv文件并对其进行一些处理。但是,我得到标题中指定的错误。完整的跟踪信息可以在下面看到:

Error using feof
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in vicon.DataLoaderVICON/loadDataGroundTruth (line 99)
            while ((~feof(fid)) & (~bIdFound))

Error in vicon.DataLoaderVICON (line 82)
            obj.loadDataGroundTruth() ;

Error in vicon.DataLoaderVICONEdges (line 39)
            obj = obj@vicon.DataLoaderVICON(varargin{:})

Error in sequence.SequenceVICON (line 51)
            obj.DataLoader = vicon.DataLoaderVICONEdges(directory,...

Error in Lshape0001 (line 21)
seq              = sequence.SequenceVICON(SEQUENCE_NAME,...

我怀疑的问题在此行:

 while ((~feof(fid)) & (~bIdFound))

在有人告诉我这样做之前:我已经使用sudo权限启动了Matlab 2017b(Ubuntu 16.04),并且已经将整个文件夹添加到路径(及其子文件夹)中。

谢谢。

1 个答案:

答案 0 :(得分:0)

知道了,要感谢用户obchardon的贡献。

我注意到该路径中也包含了./,事实并非如此。我尝试运行的文件可能是在Windows计算机中编写的,因此路径中具有不同的符号/符号。一旦我打印了它试图从中加载文件的路径,我注意到它不应该带有./。我将其从路径中删除,并且有效。