フィルターのクリア

create a new pattern with a string

1 回表示 (過去 30 日間)
Elysi Cochin
Elysi Cochin 2017 年 10 月 4 日
コメント済み: darshana alaiya 2023 年 4 月 2 日
i have a string pattern as below of length 24
str1 = 'AAAAAABBBBBBCCCCCCDDDDDD'
now i want to create a new pattern from the str1 with the length i give,
if i give length of new pattern as 72 answer should be
str2 = 'AAAAAABBBBBBCCCCCCDDDDDDAAAAAABBBBBBCCCCCCDDDDDDAAAAAABBBBBBCCCCCCDDDDDD'
that is it should repeat pattern in str1 upto the limit i want
if i give 84 answer should be
str3 = 'AAAAAABBBBBBCCCCCCDDDDDDAAAAAABBBBBBCCCCCCDDDDDDAAAAAABBBBBBCCCCCCDDDDDDAAAAAABBBBBB'
  1 件のコメント
darshana alaiya
darshana alaiya 2023 年 4 月 2 日
I want matrix with repeated pattern in 1st 3rd and 5th row.
for eg. 1 18 25 0 0 0 0 0 0
3 23 27 0 0 0 0 0 0
0 0 0 5 28 29 0 0 0
0 0 0 7 33 31 0 0 0
so on...

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 10 月 4 日
編集済み: Andrei Bobrov 2017 年 10 月 4 日
m = 84;
[s,~,c] = unique(str1,'stable');
n = numel(c);
out = s(c(rem(0:m-1,n)+1));
or
m = 84;
k = repmat(str1,1,ceil(m/numel(str1)));
out = k(1:m);

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 10 月 4 日
temp = repmat(str1, ceil(Count/length(str1))) ;
str3 = temp(1:Count);
  2 件のコメント
Walter Roberson
Walter Roberson 2017 年 10 月 4 日
temp = repmat(str1, 1, ceil(Count/length(str1))) ;
str3 = temp(1:Count);
Andrei Bobrov
Andrei Bobrov 2017 年 10 月 4 日
+1

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

カテゴリ

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