Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Guillaume
Guillaume el 22 de Ag. de 2019
Editada: Guillaume el 22 de Ag. de 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 comentarios
Guillaume
Guillaume el 22 de Ag. de 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}'

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by