Extracting nth element of nested cell array
조회 수: 8 (최근 30일)
이전 댓글 표시
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
답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!