Combining a character array and matrix

12 Ansichten (letzte 30 Tage)
Conner Carriere
Conner Carriere am 10 Feb. 2021
Kommentiert: Conner Carriere am 10 Feb. 2021
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 10 Feb. 2021
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 Kommentar
Conner Carriere
Conner Carriere am 10 Feb. 2021
Thank you, this worked as well as your answer to my other post! Cheers!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by