Convert a string array to numbers (RGB triplets)

조회 수: 3 (최근 30일)
Ana Egatz-Gomez
Ana Egatz-Gomez 2023년 4월 28일
댓글: Ana Egatz-Gomez 2023년 4월 28일
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
VBBV
VBBV 2023년 4월 28일
이동: VBBV 2023년 4월 28일
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 2023년 4월 28일
Thank you!

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2023년 4월 28일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by