creating a function that reads into the directory

조회 수: 1 (최근 30일)
WILLBES BANDA
WILLBES BANDA 2020년 5월 30일
댓글: Ameer Hamza 2020년 5월 30일
Hi, i want to create a function that uses the file prefix, directory name and file type as inputs to pick up files that i want to process from my directory. Below is my code but it is not working, it says Dot indexing is not supported for variables of this type. As an example, i might be looking for all excel spreadsheets that have the prefix DynamicData in my directory pwd, but i want my code to give the output as TableFiles. Please help !!!
FilePrefix ='DynamicData';
DirectoryName = pwd;
filetype='.xlsx'
FileList = strcat(['DirectoryName','FilePrefix','*','filetype']);
TableFiles = {};
for LenFlLst = 1:numel(FileList)
TableFiles = {FileList.name};
end

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 30일
you also need to use dir() to get actual file names. Try this code
% FilePrefix ='DynamicData';
FilePrefix ='test';
DirectoryName = pwd;
filetype='.xlsx';
FileList = fullfile(DirectoryName,[FilePrefix,'*',filetype]); % fullfile is better to construct file paths
FileList = dir(FileList);
TableFiles = cell2table({FileList.name}.', 'VariableNames', {'Filenames'});
  댓글 수: 2
WILLBES BANDA
WILLBES BANDA 2020년 5월 30일
Thank you honourable, it works perfectly fine
Ameer Hamza
Ameer Hamza 2020년 5월 30일
I am glad to be of help!

댓글을 달려면 로그인하십시오.

추가 답변 (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