Indexing Cell Array created by RegExp, sorting file names
显示 更早的评论
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
回答(1 个)
Azzi Abdelmalek
2013-11-15
编辑:Azzi Abdelmalek
2013-11-15
Maybe you want
getrest = regexp(names,'resting_ABC_\d+.dat','match');
files=cellfun(@(x) x{1},getrest(~cellfun('isempty',getrest)),'un',0)
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!