MATLAB: Extracting first letter from the cell

arraycell arraycellfunextractingfisrtletterinitials

hello,
I have two cell arrays: nam1 = {'John', 'Adam', 'Emma'} nam2 = {'Doe', 'Willson', 'Brown'}
I want to create one array with initials, like this: init = {'JD', 'AW', EB'}
I tried extracting first letters from each array like this:
if true
% code
end
ininam1 = cellfun (@(x) x(1),nam1,'un',0)
ininam2 = cellfun (@(x) x(1),nam2,'un',0)
but this already fails (Index exceeds array bounds). Can you help me with this? Also combining these two arrays together?
Thanks in advance!
K.

Best Answer

Hi,

nam1 = {'John', 'Adam', 'Emma'} ;
nam2 = {'Doe', 'Willson', 'Brown'};
ininam1 = strcat(nam1{1}(1),nam2{1}(1))