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 件のコメント
Kinjal Mutha
Kinjal Mutha 2019 年 8 月 22 日
Is the issue becuase I am working on 2011 version right now?
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 Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by