Skip to content

Commit

Permalink
Table/read: improve octave compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dlegland committed Mar 26, 2021
1 parent 251ca77 commit 4cfc7c6
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions matStats/@Table/read.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,30 @@

%% Open file

[filePath, baseName, ext] = fileparts(fileName);

% open file
f = fopen(fileName, 'r');
if f == -1
% try to add a txt extension if it was forgotten
fileName2 = [fileName '.txt'];
f = fopen(fileName2, 'r');
fullFileName = fullfile(filePath, [baseName ext]);

% if file does not exist, try to add the path to the list of sample files
if exist(fullFileName, 'file') == 0 && isempty(filePath)
% retrieve the path to sample files
[filePath, ~] = fileparts(mfilename('fullpath'));
filePath = fullfile(filePath, 'private');

% create newfile path
fullFileName = fullfile(filePath, [baseName ext]);

% if file still does not exist, try to add default '.txt' extension
if exist(fullFileName, 'file') == 0 && isempty(ext)
ext = '.txt';
fullFileName = fullfile(filePath, [baseName ext]);
end
end

f = fopen(fullFileName, 'r');
if f == -1
error('Couldn''t open the file %s', fileName);
error('Couldn''t open the file %s', [baseName ext]);
end

% keep filename into data structure
Expand Down

0 comments on commit 4cfc7c6

Please sign in to comment.