Extracting nth element of nested cell array
22 views (last 30 days)
Show older comments
I'm trying to extract the nth element of a nested cell array. The nested cell array is of filenames in a directory that are delimited with underscores. I want to extract the 3rd element from each filename and put it into a vector.
Here's my code:
filesInDirectory = dir('InsertDirectoryHere');
filenames = {filesInDirectory.name};
filenameSplit = regexp(filenames, '_', 'split');
The contents of 'filenameSplit' is 33 columns with a 1x5 cell array in each column. I want to extract the 3rd cell in each column and put it into a vector. Here's my attempt:
id = filenameSplit{:}{3};
This does not work, but I can see all elements with the following command (I just don't know how to subset to keep only the 3rd element in each cell array):
filenameSplit{:}
I've read through the forums for similar problems, but I can't find a way to generalize their answers to my problem. I'm new to Matlab so any help would be greatly appreciated.
0 Comments
Answers (1)
See Also
Categories
Find more on Logical 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!