Combining a character array and matrix

15 次查看(过去 30 天)
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

更多回答(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