Effacer les filtres
Effacer les filtres

Does .xls file location matter in order to open and access data from the the file in matlab?

2 vues (au cours des 30 derniers jours)
I want to access columns from multiple excel sheets which are in some folder on D drive and my matlab application folder is on C drive.
When I use
files = dir('*.xls');
num = length(files);
I get an empty array and num = 0, when my current folder is D drive folder containing all the excel files.
How can I fix this?
Also further how can I read a particular column from each excel and store it in an array?

Réponse acceptée

Guillaume
Guillaume le 22 Août 2019
Modifié(e) : Guillaume le 22 Août 2019
"Does .xls file location matter in order to open and access data from the the file in matlab?"
No. Matlab can access files (not just xls) anywhere on your disk.
As for your question. Always use absolute paths instead of relying on the current folder. Despite what you say, if there are excel fles in D:\ and dir doesn't return anything with the syntax you use, then your current folder is not D:. You can check your current folder with:
pwd
But if you use absolute path, it doesn't matter what your current folder is. You'll always been checking the folder you meant:
folder = 'D:';
filelist = dir(fullfile(folder, '*.xls'));
numfiles = numel(filelist)
If dir still finds nothing, then there are no xls files in that folder (perhaps, they're xlsx files).
  3 commentaires
Kinjal Mutha
Kinjal Mutha le 22 Août 2019
Is the issue becuase I am working on 2011 version right now?
Guillaume
Guillaume le 22 Août 2019
No. While R2011 is certainly very old, it wouldn't affect which files are visible. The only thing you can't do is the '\**.xls*' that Image Analyst mention to look into subfolders.
What is the output of:
allfiles = dir('D:\*.*');
{allfiles(~[allfiles.isdir]).name}'

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by