Indexing Cell Array created by RegExp, sorting file names
2 views (last 30 days)
Show older comments
I've created a cell array of the names of certain files in a selected folder using the following
files = dir('*.dat');
names = {files.name};
Now that I have my file names stored, I want to sort them by their names. Firstly I want to identify the file names of the sort, 'resting_ABC_1.dat'
So I used regexp to find these names and then filled the empty [] sections of the cell array using the following
getrest = regexp(names,'resting_ABC_(\d*).dat','tokens');
emptyIndex = cellfun('isempty',getrest);
getrest(emptyIndex) = {0};
I don't have much experience with cell arrays, and I'm having trouble identifying the row, column of the cell array not equal to zero. I could then use these numbers to extract the name from my names cell array and process only the data fitting my specifications. I want to be able to apply this code to any folder and have it find and process the data with my file name specifications. Any ideas would be greatly appreciated
0 Comments
Answers (1)
Azzi Abdelmalek
on 15 Nov 2013
Edited: Azzi Abdelmalek
on 15 Nov 2013
Maybe you want
getrest = regexp(names,'resting_ABC_\d+.dat','match');
files=cellfun(@(x) x{1},getrest(~cellfun('isempty',getrest)),'un',0)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!