%% Access Character Vectors in Cell Array
% To access character vectors in a cell array, index into it using curly braces, {}. Extract the contents of the first cell and store it as a character vector.

C = {'Li','Sanchez','Jones','Yang','Larson'};
chr = C{1}

%
% Assign a different character vector to the first cell.

C{1} = 'Yang'

%
% To refer to a subset of cells, instead of their contents, index using smooth parentheses.

C(1:3)

%
% While you can access the contents of cells by indexing, most functions that accept cell arrays as inputs operate on the entire cell array. For example, you can use the strcmp function to compare the contents of C to a character vector. strcmp returns 1 where there is a match and 0 otherwise.

TF = strcmp(C,'Yang')

%
% You can sum over TF to find the number of matches.

num = sum(TF)

%
% Use TF as logical indices to return the matches in C. If you index using smooth parentheses, then the output is a cell array containing only the matches.

M = C(TF)

% Copyright 2019 The MathWorks, Inc.