MATLAB: Reading data after Importing text files into variables with the same name

variable names/ready file

I have this code from a on line source
files = dir( '*.txt' ) ;
nFiles = length( files ) ;
names = cell( nFiles, 1 ) ;
data = cell( nFiles, 1 ) ;
for dId = 1 : nFiles
names{dId} = files(dId).name ;
fId = fopen( files(dId).name, 'r' ) ;
cols = textscan( fId, '%f %f', 'headerlines', 1 ) ;
data{dId} = [cols{:}] ;
fclose( fId ) ;
end
can anybody help me how can I then read my files to reach the data set in each individual file ? Thanks

Best Answer

You've read the files already, you've got nFiles cells of a 2D array that's Nx2 for each file where N may be a different length.
To address the data of a given file, "use the curlies, Luke!" --
xy=data{idx};
will return the full array for the idx th entry, idx=1:nFiles
To refer to a subset within the array, follow with a set of indices in "normal" parentheses--
x=data{idx}(:,1);
would be the first column of the above array.
See
doc cell % and links to "addressing cell contents" for the details
and look at the "Getting Started" section on data types for cell arrays and tutorial information.