필터 지우기
필터 지우기

Combining a character array and matrix

조회 수: 7 (최근 30일)
Conner Carriere
Conner Carriere 2021년 2월 10일
댓글: Conner Carriere 2021년 2월 10일
I was wondering if there was a way to combine a char array and a matrix
I have this character array
MwC =
9×1 char array
'w'
'b'
'y'
'b'
'w'
'r'
'y'
'r'
'b'
and this matrix
newcoords =
1
2
3
4
5
6
7
8
9
I have tried something like [newcoords, MwC] but that does not work and it outputs weird symbols
I need to be able to do something like
combined(1,2)= 'w'
I am ok with changing 'w' into a variable if that would work better

채택된 답변

Walter Roberson
Walter Roberson 2021년 2월 10일
Your desired output is not clear.
MwC = [
'w'
'b'
'y'
'b'
'w'
'r'
'y'
'r'
'b'];
newcoords = (1:9).';
newcoords + string(MwC)
ans = 9×1 string array
"1w" "2b" "3y" "4b" "5w" "6r" "7y" "8r" "9b"
compose('%d %s', newcoords, MwC)
ans = 9x1 cell array
{'1 w'} {'2 b'} {'3 y'} {'4 b'} {'5 w'} {'6 r'} {'7 y'} {'8 r'} {'9 b'}
char(ans)
ans = 9x3 char array
'1 w' '2 b' '3 y' '4 b' '5 w' '6 r' '7 y' '8 r' '9 b'
compose("%d %s", newcoords, MwC)
ans = 9×1 string array
"1 w" "2 b" "3 y" "4 b" "5 w" "6 r" "7 y" "8 r" "9 b"
table(newcoords, MwC)
ans = 9x2 table
newcoords MwC _________ ___ 1 w 2 b 3 y 4 b 5 w 6 r 7 y 8 r 9 b
  댓글 수: 1
Conner Carriere
Conner Carriere 2021년 2월 10일
Thank you, this worked as well as your answer to my other post! Cheers!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by