How to split a cell array by finding certain cells
이전 댓글 표시
Say I have a cell that is something like
testCell = {'start', 1, 2, 3, 'start', 4, 5, 'start', 6, 7, 8, 9}
How can I split it into several separate cells so that I get something like
test1 = {'start', 1, 2, 3}
test2 = {'start', 4, 5}
test3 = {'start', 6, 7, 8, 9}
In the final program the length of the original cell, as well as the number of times 'start' appears isn't constant, and the data in between is sometimes numbers, sometimes strings, and occasionally has some empty cells (which can't be deleted)
Any help would be appreciated
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2015년 8월 3일
편집: Andrei Bobrov
2015년 8월 3일
accumarray(cumsum(strcmp(testCell,'start'))',...
(1:numel(testCell))',[],@(x){testCell(x)})
카테고리
도움말 센터 및 File Exchange에서 Testing Frameworks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!