Combining a character array and matrix

12 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by