open a list fo file with fopen???
3 views (last 30 days)
Show older comments
It gives problem for the fileID.
File_info = dir('*.lis');
filename = {File_info.name};
[m,nfile]= size(filename);
for ifile= 1:nfile
delimiter = {' ',';'};
formatSpec = '%s%s%s%s%s%s%[^\n\r]';
fileID=fopen(filename{ifile}, 'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true, 'ReturnOnError', false);
fclose(fileID);
end
3 Comments
Image Analyst
on 22 Oct 2016
Well it was a step along the way. I'm sure there was something in there about attaching your data so people can reproduce your situation. I guess you didn't read it because you didn't attach the file. You didn't even attach all the red text of your error message like I asked directly in the comment. Did you even look at all I could do (given what you've provided) in my answer below? Come on, make it easy for us to help you not hard.
Answers (1)
Image Analyst
on 22 Oct 2016
Here's some improved code:
delimiter = {' ',';'};
formatSpec = '%s%s%s%s%s%s%[^\n\r]';
File_info = dir('*.lis');
allFileNames = {File_info.name};
[m,nfile]= size(allFileNames)
numFilesProcessed = 0;
for ifile= 1:nfile
thisFileName = fullfile(pwd, allFileNames{ifile});
fprintf('Processing %s\n', thisFileName);
fileID=fopen(allFileNames{ifile}, 'r');
if fileID ~= -1
% File is good.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true, 'ReturnOnError', false);
fclose(fileID);
numFilesProcessed = numFilesProcessed + 1;
else
message = sprintf('Cannot open this file:\n%s', thisFileName);
uiwait(warndlg(message));
end
end
fprintf('Done!\nProcessed %d files.\n', numFilesProcessed);
0 Comments
See Also
Categories
Find more on Low-Level File I/O in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!