필터 지우기
필터 지우기

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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by