No such file or directory for a found file.

9 vues (au cours des 30 derniers jours)
Stephen West
Stephen West le 20 Oct 2021
Réponse apportée : Voss le 20 Oct 2021
files = dir("Aero Lab Airfoil Testing/2002 Aero Lab 2 - Group Data/*.csv");
for n=1:length(files)
load(files(n).name, "-ascii");
end
I have this code to load in and read several .csv files at once. When I run it, I get the error
>> airfoil
Error using load
Unable to read file 'AirfoilPressure_S301_1.csv'. No such file or directory.
Error in airfoil (line 3)
load(files(n).name, "-ascii");
I'm not sure how there could be an issue with the file not existing when the code is locating the file in the directory. Any help would be appreciated.

Réponses (2)

Image Analyst
Image Analyst le 20 Oct 2021
Try this:
topLevelFolder = fullfile(pwd, 'Aero Lab Airfoil Testing/2002 Aero Lab 2 - Group Data');
filePattern = fullfile(topLevelFolder, '**\*.csv');
fileList = dir(filePattern);
for k = 1 : numel(fileList)
thisFullFileName = fullfile(fileList(k).folder, fileList(k).name);
fprintf('Reading %s...\n', thisFullFileName);
data = readmatrix(thisFullFileName); % or csvread()
end

Voss
Voss le 20 Oct 2021
files(n).name is just the file name, not the full path to the file, so you have to cd to the directory and/or refer to the file by its full path

Catégories

En savoir plus sur Airfoil tools 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!

Translated by