フィルターのクリア

How to concatenate string array to matrix?

23 ビュー (過去 30 日間)
Hyon Kim
Hyon Kim 2017 年 3 月 1 日
コメント済み: Walter Roberson 2017 年 3 月 2 日
I have a question regarding adding a string array to a matrix. i.e.
string array = {'A','B','C'}; B = eye(3); I want to concatenate those two in column, i.e. I want to get is eventually;
[1,0,0,A; 0,1,0,B; 0,0,1,C]
Thank you so much for your help in advance! Best,

回答 (1 件)

Adam
Adam 2017 年 3 月 1 日
編集済み: Adam 2017 年 3 月 1 日
stringArray = {'A','B','C'};
B = eye(3);
result = [num2cell(B) stringArray'];
is the best you can do, resulting in a cell array.
[1,0,0,A; 0,1,0,B; 0,0,1,C]
is not a valid array in Matlab unless A, B and C are variables, but since you are talking about a cell array of chars I assume that is not the case.
  4 件のコメント
Hyon Kim
Hyon Kim 2017 年 3 月 2 日
I see. Thank you so much for your help!
Walter Roberson
Walter Roberson 2017 年 3 月 2 日
tables can also mix strings with numbers, but they are pretty much implemented as cell arrays.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by