Use wildcards with excel

4 visualizzazioni (ultimi 30 giorni)
Kajover
Kajover il 13 Ott 2015
Modificato: Walter Roberson il 13 Ott 2015
Hi. I am trying to read the first column of a sheet that contains a list of filepaths and look inside the folders for *.xlsx and open them. Unfortunately I get an error message. Do you have an idea how to solve this? Thank you very much in advance.
[~, entry] = xlsread(workbookFile,sheetName);
for i=1
sourceDir = xlsread(entry{i,1}); %error message here
sourceFiles = dir(fullfile(sourceDir, '*.xlsx'));
data(:,1) = xlsread(sourceFiles, 1, [entry{i,3} ':' entry{i,3}]);
...
Alternative Code:
data(:,1) = xlsread(dir(fullfile(entry{i,1}, '*.xlsx')), 1, [entry{i,3} ':' entry{i,3}]);
Error: File name must be a string
data(:,1) = xlsread(dir(fullfile(entry(i,1), '*.xlsx')), 1, [entry{i,3} ':' entry{i,3}]);
Error: Error using dir. Function is not defined for 'cell' inputs.
  2 Commenti
Walter Roberson
Walter Roberson il 13 Ott 2015
What does
class(entry{1,1})
show?
Kajover
Kajover il 13 Ott 2015
it says 'char'

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 13 Ott 2015
Modificato: Walter Roberson il 13 Ott 2015
xlsread() cannot read directories ir wildcards. You need to use dir() to find the contents of the folders and read the files one by one.
The output of dir() is a structure not a list of file names

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by