concatenate matrixs

조회 수: 2 (최근 30일)
li xinjun
li xinjun 2011년 12월 7일
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
li xinjun
li xinjun 2011년 12월 7일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 12월 7일
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
li xinjun
li xinjun 2011년 12월 15일
Thank you very mucch.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by