one two three four

2 次查看(过去 30 天)
James Knight
James Knight 2019-11-7
评论: Rena Berman 2019-12-12
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
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
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 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by