How do you create a string from two strings by intersecting them char by char to form a new word using a loop?
1 次查看(过去 30 天)
显示 更早的评论
str1 = 'Hello'
str2 = 'Canada'
strNew = 'CHaenlaldoa' %This is how the new word should look like.
Thank you in advance!
4 个评论
Kevin Chng
2018-10-27
for i = [1:numel(str2)]
try to look at the link below:
Do you notice any problem with your for-loop?
采纳的回答
Stephen23
2018-10-27
编辑:Stephen23
2018-10-27
Loop not required, just use indexing:
Method one:
>> str1 = 'Hello';
>> str2 = 'Canada';
>> strN = [str1,str2];
>> strN([2:2:end,1:2:end]) = strN
strN = CHaenlaldoa
Method two:
>> strN = str2([1,1],:);
>> strN(1,2:end) = str1;
>> strN = strN(2:end)
strN = CHaenlaldoa
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!