Borrar filtros
Borrar filtros

Combining a character array and matrix

8 visualizaciones (últimos 30 días)
Conner Carriere
Conner Carriere el 10 de Feb. de 2021
Comentada: Conner Carriere el 10 de Feb. de 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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by