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

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

 採用された回答

dpb
dpb 2015 年 8 月 20 日
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.

3 件のコメント

Thanks dpb but its not givng me my data which is 123455*23 its just giving me single number x = data{1}(:,1)
x =
6
I will try it again
dpb
dpb 2015 年 8 月 21 日
data{1}(:,1) will return all rows of the first column of the first cell in the array data. That would be a single value iff size(,1) of that cell array is unity.
Not being able to see your terminal from here [ :) ] it's a little hard to know what, precisely, is happening, but let's start with
which data
which data(1)
which data{1}
to see what you actually have...
amberly hadden
amberly hadden 2015 年 8 月 21 日
its little trivial for me to work with it so I decided to just read all files one by one and process them. Thanks for your suggestions and help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Weather and Atmospheric Science についてさらに検索

質問済み:

2015 年 8 月 20 日

コメント済み:

2015 年 8 月 21 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by