MATLAB Answers

one two three four

4 ビュー (過去 30 日間)
James Knight
James Knight 2019 年 11 月 7 日
Commented: Rena Berman 2019 年 12 月 12 日
I have two strings stored in a variable
I want to repeat B to make it the same length as A

  3 件のコメント

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 2019 年 11 月 7 日
If Thorsten hadn't posted an answer, I was going to close the question as it's a duplicate of
Please don't waste people time by asking the same question twice.
Rena Berman
Rena Berman 2019 年 12 月 12 日
(Answers Dev) Restored edit

サインイン to comment.

件の回答 (1)

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 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。


Translated by