MATLAB: Horzcat error while using ‘ ‘

horzcat

names=['john'; 'ravi'; 'mary'; 'xiao']
howdy=char('10', '20', '30' ,'40')
result=[howdy, ' ', names] % ' ' in order to seperate columns
I wanna create result as
john 10
ravi 20
mary 30
xiao 40
but result=[howdy, ' ', names] gives horzcat error. How can I fix this?

Best Answer

names=['john'; 'ravi'; 'mary'; 'xiao']
howdy=['10'; '20'; '30' ;'40']
result=[names repmat(' ',4,1) howdy]