Borrar filtros
Borrar filtros

concatenate matrixs

1 visualización (últimos 30 días)
li xinjun
li xinjun el 7 de Dic. de 2011
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?
  1 comentario
li xinjun
li xinjun el 7 de Dic. de 2011
And also,I need Num1=[1,2.32322232,4;222,0,-Inf] show like [1.00,2.32,4.00;222.00,0.00,-Inf] in the excel.I know the length of each elements between char1 and Num1 are not the same ,even each elements of the Num1 isn't the same longth,but I also hope I can achieve.

Iniciar sesión para comentar.

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 7 de Dic. de 2011
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);
  1 comentario
li xinjun
li xinjun el 15 de Dic. de 2011
Thank you very mucch.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by