one two three four

1 view (last 30 days)
James Knight
James Knight on 7 Nov 2019
Commented: Rena Berman on 12 Dec 2019
I have two strings stored in a variable
EG
A='HELLO'
B='TEST'
I want to repeat B to make it the same length as A
EG
A='HELLOWORLD'
B='TESTTESTTE'
  3 Comments
Rena Berman
Rena Berman on 12 Dec 2019
(Answers Dev) Restored edit

Sign in to comment.

Accepted Answer

Thorsten
Thorsten on 7 Nov 2019
Replicate B such that is is as long or longer than A, then cut it to the length of A;
B = repmat(B, 1, ceil(numel(A)/numel(B)));
B = B(1:numel(A));

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by