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

1 次查看(过去 30 天)
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?

采纳的回答

Guillaume
Guillaume 2019-8-22
编辑:Guillaume 2019-8-22
"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 个评论
Guillaume
Guillaume 2019-8-22
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}'

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by