MATLAB: Batch process text files

multidimentional array.

I am trying to save series of cells in a loop. I need to batch process text files having a 10 lines of both numbers and characters ( 12 12 34 54 rr). I am trying to save them in cell array so that i can access them later. The code I have written is giving error :
error : Error using textscan Invalid file identifier. Use fopen to generate a valid file identifier.
This code is working perfectly without the loop. Please help I am new to matlab. Is there any other better method of saving the files.
My code :
input_directory = 'd2/';
filelabels = dir([input_directory '*.txt']);
wav_label1 = cell(12,12);
wav_label2 = cell(12,12);
for i = 1: numel(filelabels)
fileName = filelabels(i).name;
fid = fopen(fileName);
results{i}= textscan(fid,'%f %f %f ........
%s','HeaderLines',2,'Delimiter',',','CollectOutput',1);
fclose(fid);
%testscan is giving output as a cell{{1,1}{1,2}} as I have numbers
%and characters both in text file
wav_label1{i} = results{1,1};
wav_label2{i} = results{1,2};
end
Thanks

Best Answer

You can use -
fileName = [input_directory filelabels(i).name];
That should solve the issue.