필터 지우기
필터 지우기

I have a string array ["Black" "Brown" "Red" "Orange" "Yellow" "Green" "Blue"] and I want to replace the colors with values 0, 0 0, 0 0 0, ... until i get to 0 0 0 0 0 0 0.

조회 수: 4 (최근 30일)
Array should look like [0, 0 0, 0 0 0, 0 0 0 0, 0 0 0 0 0, 0 0 0 0 0 0, 0 0 0 0 0 0 0] instead of the original one containing colors.I am unsure how to do it.
  댓글 수: 2
the cyclist
the cyclist 2018년 2월 18일
편집: the cyclist 2018년 2월 18일
Can you add a little more detail? This is not Twitter, so please make it easy on us.
For example, is the output a numeric matrix, like
[0 0 0 0 0 ...]
? Or is it a string matrix, such as ...
out = ["0" "0 0" "0 0 0"]
Also, does it matter if a color is repeated?

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

답변 (1개)

the cyclist
the cyclist 2018년 2월 18일
Here is one way:
s = ["Black" "Brown" "Red" "Orange" "Yellow" "Green" "Blue"];
L = length(s);
Z = strings(1,7);
Z(1) = "0";
for ns = 2:L
Z(ns) = strcat(Z(ns-1)," 0");
end
I don't have much experience working with strings, so I expect there is a more efficient way.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by