2012-03-15 5 views
5

나는 특정 디렉토리의 모든 파일을 포함하는 배열을 가지고 있습니다. .txt 확장명으로 끝나는 모든 파일 항목을 제거하고 싶습니다. 이것은 내가 배열에서 요소를 제거합니다 matlab

function fileList = removeElements(fileArray)  

    for idx = 1:numel(fileArray) 

    if (strfind(fileArray(idx),'.txt') > 0) 
    display('XX'); 
    fileArray(idx) =[]; 
    end  

    end  

end 

를 작성한하지만 난

??? Undefined function or method 'gt' for input arguments of type 'cell'. 
    Error in ==> removeElements at 6 
     if(strfind(fileArray(idx),'.bmp') > 0) 

사람이

답변

1

>0이 경우에 잘못 나에게 도움을 주시기 바랍니다 수있는 오류를 얻을 것입니다. 대신 ~isempty(strfind(....))을 사용하십시오.

2

당신은 하나의 라인 건설

% strip-out all '.txt' filenames 
newList = oldList(cellfun(@(c)(isempty(strfind('.txt',c))),oldList)); 

파일 이름이 하지이 '가 .txt'를 포함하지 않으면 IsEmpty 함수() 공사가 true를 반환과 기능에 대한 루프를 방지 할 수 있습니다. oldList (...) 구조체는, isempty 구조체가 true를 돌려주는 oldList의 요소의 셀 배열을 돌려줍니다.

관련 문제