How to fix 'Error using contains First argument must be a string array, character vector, or cell array of character vectors.'

조회 수: 147 (최근 30일)
I am getting the error:
Error using contains First argument must be a string array, character vector, or cell array of character vectors.
Error in xlsxdatatostructurearray/getgastablelisting (line 17) TF1 = contains(Directory{d},FilePrefix,'IgnoreCase',true);
Error in xlsxdatatostructurearray (line 25) for l = 1:length(getgastablelisting(FilePrefix, DirectoryName, filetype))
please help.
This is the code that is giving the error.
function [LookupTableFiles] = getgastablelisting(FilePrefix, DirectoryName, filetype)
LookupTableFiles = {};
Directory = dir(DirectoryName);
Directory = struct2cell(Directory);
for d = 1:length(Directory)
TF1 = contains(Directory{d},FilePrefix,'IgnoreCase',true);
TF = contains(Directory{d},filetype,'IgnoreCase',true);
if (TF1 == 1) && (TF == 1)
LookupTableFiles = {LookupTableFiles Directory{d}};
end
end
end

채택된 답변

Sugar Daddy
Sugar Daddy 2020년 6월 1일
편집: Sugar Daddy 2020년 6월 1일
There are 6 fields in structure i.e. name, folder, data, bytes, isdir and datenum
three of them are str and two of them are numbers
when you convert struct2cell it puts each fileld in a new cell giving you the size of 6xactual number of files or folders
so
Directory{1,d}
will give you file name and can work with contains
Directory{2,d}
will give you folder name and can work with contains

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by