create a new pattern with a string
이전 댓글 표시
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
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...
채택된 답변
추가 답변 (1개)
Walter Roberson
2017년 10월 4일
temp = repmat(str1, ceil(Count/length(str1))) ;
str3 = temp(1:Count);
댓글 수: 2
Walter Roberson
2017년 10월 4일
temp = repmat(str1, 1, ceil(Count/length(str1))) ;
str3 = temp(1:Count);
Andrei Bobrov
2017년 10월 4일
+1
카테고리
도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!