www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ReturnIndicesinCellArrayExample.m

    %% Return Indices in Cell Array  
% Find the occurrences of a pattern in a character vector. Force |strfind| to 
% return the indices of those occurrences in a cell array. Then display the 
% indices.   

%% 
% Create a character vector and find the occurrences of the pattern |ain|. 
str = 'The rain in Spain.';
k = strfind(str,'ain','ForceCellOutput',true)  

%% 
% |strfind| returns a scalar cell that contains a numeric array, which contains
% indices of occurrences of the pattern |ain| in |str|. To access the numeric
% array within the cell, use curly braces. 
k{1}