Convert a string array to numbers (RGB triplets)

3 visualizaciones (últimos 30 días)
Ana Egatz-Gomez
Ana Egatz-Gomez el 28 de Abr. de 2023
Comentada: Ana Egatz-Gomez el 28 de Abr. de 2023
I have the string array named Colores, and I want to convert it to a 7x3 numerical array I can use to pass RGB values to scatter plotting functions. I am stuck here. Can anyone please help?
Colores 7×1 string array
"0 0 0.17241"
"0 0 1"
"0 0 1"
"0 0 1"
"0 0 1"
"1 0.82759 0"
"0 0 1"
"1 0.82759 0"
  2 comentarios
VBBV
VBBV el 28 de Abr. de 2023
Movida: VBBV el 28 de Abr. de 2023
Colores = ["0 0 0.17241"; "0 0 1"; "0 0 1"; "0 0 1"; "0 0 1"; "1 0.82759 0"; "0 0 1"; "1 0.82759 0"]
Colores = 8×1 string array
"0 0 0.17241" "0 0 1" "0 0 1" "0 0 1" "0 0 1" "1 0.82759 0" "0 0 1" "1 0.82759 0"
fprintf('%s\n', Colores)
0 0 0.17241 0 0 1 0 0 1 0 0 1 0 0 1 1 0.82759 0 0 0 1 1 0.82759 0
Ana Egatz-Gomez
Ana Egatz-Gomez el 28 de Abr. de 2023
Thank you!

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 28 de Abr. de 2023
S = ["0 0 0.17241"; "0 0 1"; "0 0 1"; "0 0 1"; "0 0 1"; "1 0.82759 0"; "0 0 1"; "1 0.82759 0"]
S = 8×1 string array
"0 0 0.17241" "0 0 1" "0 0 1" "0 0 1" "0 0 1" "1 0.82759 0" "0 0 1" "1 0.82759 0"
M = double(split(S))
M = 8×3
0 0 0.1724 0 0 1.0000 0 0 1.0000 0 0 1.0000 0 0 1.0000 1.0000 0.8276 0 0 0 1.0000 1.0000 0.8276 0

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by