How to read in specific File names?

2 ビュー (過去 30 日間)
Oliver Bunn
Oliver Bunn 2017 年 2 月 6 日
コメント済み: Oliver Bunn 2017 年 2 月 6 日
I have a matrix containing a list of .csv files from a specific folder.
There are two different files however, one which ends in '_DE.csv' and the other ending with '_NDE.csv'.
What code can I use to specifically read them individually dependent on whether it is DE or NDE? This needs to be for i number of files.
An idea I think is to use if to produce a matrix of equal dimensions but with 1's and 0's for the specific file I want then multiply, but any attempt at this has failed so far.

採用された回答

Stephen23
Stephen23 2017 年 2 月 6 日
編集済み: Stephen23 2017 年 2 月 6 日
>> C = {'A_NDE.csv';'B_DE.csv';'C_DE.csv';'E_NDE.csv';'F_NDE.csv'};
>> T = regexpi(C,'_(N?)DE.csv$','once','tokens');
>> X = cellfun('isempty',[T{:}]) % True == NE, False == NDE
X =
0 1 1 0 0
and getting just those names:
>> C(X)
ans =
'B_DE.csv'
'C_DE.csv'
>> C(~X)
ans =
'A_NDE.csv'
'E_NDE.csv'
'F_NDE.csv'
  1 件のコメント
Oliver Bunn
Oliver Bunn 2017 年 2 月 6 日
Perfect! Thank you

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

その他の回答 (1 件)

Guillaume
Guillaume 2017 年 2 月 6 日
Assuming your matrix is actually a cell array of char vectors, the easiest way in R2016b is to use the new string class:
demoarray = {'file1_DE.csv', 'file2_NDE.csv', 'file3_NDE.csv', 'file4_DE.csv'};
desiredending = '_DE.csv';
filteredarray = demoarray(endsWith(string(demoarray), '_DE.csv'))
  1 件のコメント
Oliver Bunn
Oliver Bunn 2017 年 2 月 6 日
I'm using R2011b so I dont have 'endsWith'

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

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by