フィルターのクリア

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 日間)
ciro saravia
ciro saravia 2018 年 2 月 17 日
回答済み: the cyclist 2018 年 2 月 18 日
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?
ciro saravia
ciro saravia 2018 年 2 月 18 日
string matrix, out = ["0"...]

サインインしてコメントする。

回答 (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 Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by