%% Apply Function to Characters in Cell or String Array
% You can use cellfun to apply functions to cell arrays of character vectors and to string arrays. cellfun treats the two kinds of arrays identically.
% Create a cell array of character vectors that contains weekday names.

C = {'Monday','Tuesday','Wednesday','Thursday','Friday'}

%
% Create three-letter abbreviations for the names using the cellfun function. Specify a function that extracts the first three characters and returns them as a character vector. To return the abbreviations in a cell array, specify the 'UniformOutput',false name-value pair.

A = cellfun(@(x) x(1:3),C,'UniformOutput',false)

%
% You also can call cellfun on a string array. For compatibility, cellfun treats each element of a string array as though it were a character vector. If you specify a function that returns text, then cellfun returns it as a cell array of character vectors, not as a string array.
% Create abbreviations for names in a string array using cellfun.

str = ["Saturday","Sunday"]

%

B = cellfun(@(x) x(1:3),str,'UniformOutput',false)

% Copyright 2012 The MathWorks, Inc.