i have the following code,in which i am trying to find all data.m files and delete string that matches expr.
fileData = dir();
m_file_idx = 1;
filenames = {fileData.name};
index = regexp(filenames,'\w*_data.m\w*','match') ;
inFiles = filenames(~cellfun(@isempty,index));
i=1;
for idx = i : length(inFiles)
data_m_files=inFiles{i};
disp(data_m_files)
C = textread('data_m_files', '%s', 'delimiter', '\n');
expr ='\.DataType[ =]+''auto''';
C = C(cellfun(@isempty, regexp(C, expr)));
i=i+1;
end
my output is:
this_is_data.m
Error using textread (line 167)
File not found.
if i use the same code by manually entering the data_m_file name,textread works fine and i get the desired result.but when i try to put in the loop,it gives me error.am i using textread incorrectly?
thanks
Yes, you’re using
textreadincorrectly.The first argument of
textreadmust be a string containing the file name. You have specified it to be'data_m_files', so MATLAB looks for a file named “data_m_files”, which obviously does not exist.You should pass the value of
data_m_files, so remove the quotes from'data_m_files', like so:and this should work.