www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ReturnMatchesInCellExample.m
%% Return Matches in Cell % Find matches within a piece of text and return the output in a scalar % cell. % % Find words that start with c, end with t, and contain one or more vowels % between them. Return the starting indices in a scalar cell. str = 'bat cat can car coat court CUT ct CAT-scan'; expression = 'c[aeiou]+t'; startIndex = regexp(str,expression,'forceCellOutput') %% % To access the starting indices as a numeric array, index into the cell. startIndex{1} %% % Return the matching and nonmatching substrings. Each output is in its own % scalar cell. [match,noMatch] = regexp(str,expression,'match','split','forceCellOutput') %% % To access the array of matches, index into |match|. match{1} %% % To access the substrings that do not match, index into |noMatch|. noMatch{1}