MATLAB: Concatenate matrixs

MATLABmatlab answers

I have two matrixs:one is num,the other is str.Like Num1=[1,2.32322232,4;222,0,-Inf],char1=['A1';'A2'].I want concatenate them,and use 'xlswrite' to save them in a excel. My steps:
Num1=[1,2.32322232,4;222,0,-Inf];
char1=['A1';'A2'];
w=str2num(char1);
w=[w;Num1;];
xlswrite('excel',w);
But it shows : ??? Error using ==> vertcat CAT arguments dimensions are not consistent. How can I do?

Best Answer

Because you have mixed numerical and string data, you have to make your variable w a cell array if you just want to run xlswrite() once. One way to come up with the cell array with your desired format for numerical data is below.
%%Original data
Num1=[1,2.32322232,4;222,0,-Inf];
char1=['A1';'A2'];
w=textscan(sprintf('%10.2f,',Num1),'%s','delimiter',',');
w=[cellstr(char1), reshape(w{1},size(Num1,1),size(Num1,2))];
xlswrite('ExcelFile.xls',w);