Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Guillaume
Guillaume il 22 Ago 2019
Modificato: Guillaume il 22 Ago 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 Commenti
Guillaume
Guillaume il 22 Ago 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}'

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by