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

Guillaume
Guillaume 2019년 11월 7일
편집: Guillaume 2019년 11월 7일
Both A and B have changed length in your example so it's unclear why the final length is 10 characters when they started at 5 and 4 characters. It's also unclear why 'WORLD' has been added to A instead of any other combination of 5 characters.
Guillaume
Guillaume 2019년 11월 7일
If Thorsten hadn't posted an answer, I was going to close the question as it's a duplicate of https://www.mathworks.com/matlabcentral/answers/489791-repeat-the-value-of-a-variable-to-match-the-length-of-another-variable
Please don't waste people time by asking the same question twice.
Rena Berman
Rena Berman 2019년 12월 12일
(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

 채택된 답변

Thorsten
Thorsten 2019년 11월 7일

0 개 추천

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));

추가 답변 (0개)

카테고리

태그

질문:

2019년 11월 7일

댓글:

2019년 12월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by