フィルターのクリア

concatenate matrixs

1 回表示 (過去 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 Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by