Convert a string array to numbers (RGB triplets)

3 vues (au cours des 30 derniers jours)
Ana Egatz-Gomez
Ana Egatz-Gomez le 28 Avr 2023
Commenté : Ana Egatz-Gomez le 28 Avr 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 commentaires
VBBV
VBBV le 28 Avr 2023
Déplacé(e) : VBBV le 28 Avr 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 le 28 Avr 2023
Thank you!

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 28 Avr 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

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by