how to insert elements to get a new output
이전 댓글 표시
i have a character variable with elements such as
cv = '000001010011100101111'
vect = [1 2 3];
Now i want to insert the vect elements to cv after every 3 elements. So that i get
new_cv = '0001001201030111100210131111'
for understandability i insert space after 3 elements
cv = '000 001 010 011 100 101 111'
new_cv = '000 1 001 2 010 3 011 1 100 2 101 3 111 1'
The elements of vect is repeated till the length of cv
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2017년 10월 4일
cv = '000001010011100101111';
k = 3;
out = reshape([reshape(cv,k,[]);sprintf('%d',(rem(0:numel(cv)/k-1,k)+1)')],1,[]);
카테고리
도움말 센터 및 File Exchange에서 SimEvents에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!