insert and run multiple files
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dears, I tried to import multiple (.dat) files. It was not possible to read them by using (importdata or dlmread). always appear an error.where is the problem?
files = dir('*.dat');
for K = 1:length(files);
data(K,:) = dlmread(files(K).name, ';');
end ;
please, i need help.
Regards,
3 comentarios
dpb
el 13 de Jul. de 2015
Show us the script in context; it would seem that if length(files)>0 then there should be at least one file opened from the above. Ergo, one is left to conclude somehow something else is going on since the message is clear that the file doesn't actually exist.
Respuestas (1)
Image Analyst
el 14 de Jul. de 2015
I find that hard to believe. If dir() found it, then it won't subsequently say it's not there. Here, try this more robust code and tell us what it says:
folder = pwd; % Whatever folder you want.
filePattern = fullfile(pwd, '*.dat');
files = dir(filePattern);
if ~isempty(files)
numberOfFiles = length(files)
% Initiliaze data. Assume one row and 42 columns of data in each data file.
data = zeros(numberOfFiles, 42);
for K = 1:length(files)
thisFileName = fullfile(folder, files(K).name);
fprintf('Trying to open %s\n', thisFileName);
if exist(thisFileName, 'file')
% Read in row vector from file.
data(K,:) = dlmread(thisFileName, ';');
else
message = sprintf('Warning: %s does not exist', thisFileName);
uiwait(warndlg(message));
end
end
else
message = sprintf('Warning: no .dat files in folder\n%s', folder);
uiwait(warndlg(message));
end
Obviously, change 42 to however many columns there actually are in your data file.
0 comentarios
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!