Read one specific file name

Hi,
I have "TRMM_2000_01_01_newntcl.csv" and "TRMM_2000_01_0108_newntcl.csv" files in the same folder. I need to read ONLY "TRMM_2000_01_01_newntcl.csv" file but the following code reads both.
Any idea?
cd ('C:\Users\<path>')
d=dir('TRMM_*_newntcl.csv');
ymdh=cell2mat(textscan([d.name], ...
'TRMM_%4d_%2d_%2d_newntcl.csv', ...
'collectoutput',true));

回答 (2 件)

Image Analyst
Image Analyst 2015 年 4 月 24 日

0 投票

Use d(1).name to take the name of the first index, i.e., the first structure in the structure array.

1 件のコメント

Damith
Damith 2015 年 4 月 24 日
It does not do any difference. Output is still the same.

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

per isakson
per isakson 2015 年 4 月 24 日

0 投票

Replace
d=dir('TRMM_*_newntcl.csv');
by
d=dir('TRMM_*01_newntcl.csv');

3 件のコメント

Damith
Damith 2015 年 4 月 24 日
If I change to below, it only selects "TRMM_2000_01_01_newntcl.csv" file. But, I have 'TRMM_2000_01_01_newntcl.csv' upto 'TRMM_2000_12_31_newntcl.csv'
d=dir('TRMM_*01_newntcl.csv');
Any idea?
per isakson
per isakson 2015 年 4 月 24 日
編集済み: per isakson 2015 年 4 月 24 日
Your question wasn't possible to answer. You provided too little information. Now you add a new requirement.
Idea
  • formulate a rule that matches all files you want and which discriminates the rest. In your comment you tell which shall be matched, but not which should discriminated against.
  • you will find that your rule cannot be met by dir in combination with a wildcard. Something else is needed. Try replace
d=dir('TRMM_*_newntcl.csv');
by
sad = dir('TRMM_*_newntcl.csv');
cac = regexp( {sad.name}, '2000_[01]\d_[0-3]\d_' );
ism = not( cellfun( @isempty, cac ) );
d = sad(ism);
Damith
Damith 2015 年 4 月 24 日
This worked. Thanks.

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

カテゴリ

ヘルプ センター および File ExchangeLarge Files and Big Data についてさらに検索

質問済み:

2015 年 4 月 24 日

編集済み:

2015 年 4 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by