How do you create a string from two strings by intersecting them char by char to form a new word using a loop?
조회 수: 9 (최근 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에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!