open a list fo file with fopen???
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Image Analyst
le 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.
Réponses (1)
Image Analyst
le 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 commentaires
Voir également
Catégories
En savoir plus sur Low-Level File I/O dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!