Convert a string array to numbers (RGB triplets)

3 visualizzazioni (ultimi 30 giorni)
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 Commenti
VBBV
VBBV il 28 Apr 2023
Spostato: VBBV il 28 Apr 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

Accedi per commentare.

Risposta accettata

Stephen23
Stephen23 il 28 Apr 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

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by