i have a array that contains all the files in a particular directory. I want to remove all the file entries that end with the .txt extension. This is what i have written
function fileList = removeElements(fileArray)
for idx = 1:numel(fileArray)
if (strfind(fileArray(idx),'.txt') > 0 )
display('XX');
fileArray(idx) =[];
end
end
end
but i get a error
??? Undefined function or method 'gt' for input arguments of type 'cell'.
Error in ==> removeElements at 6
if( strfind(fileArray(idx),'.bmp') > 0 )
can someone please help me
Delete the contents of a particular cell by assigning an empty array to the cell, using curly braces for content indexing, {} . Delete sets of cells using standard array indexing with smooth parentheses, () .
Method 1: By using rmmissing( ) This function is used to remove missing entries or Nan values from a specified matrix.
newStr = erase( str , match ) deletes all occurrences of match in str . The erase function returns the remaining text as newStr . If match is an array, then erase deletes every occurrence of every element of match in str . The str and match arguments do not need to be the same size.
In logical indexing, you use a single, logical array for the matrix subscript. MATLAB extracts the matrix elements corresponding to the nonzero values of the logical array. The output is always in the form of a column vector. For example, A(A > 12) extracts all the elements of A that are greater than 12.
You can avoid the function and for-loop with the single line construction
% strip-out all '.txt' filenames
newList = oldList(cellfun(@(c)(isempty(strfind('.txt',c))),oldList));
The isempty() construction returns true if the filename does not include '.txt'. The oldList(...) construction returns a cell array of elements of oldList for which the isempty construction returns true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With