making upper case character with respect to the indexes

조회 수: 9 (최근 30일)
Umut Oskay
Umut Oskay 2020년 5월 24일
댓글: Image Analyst 2020년 5월 25일
indxC = [1,7];
s ='hello world';
i want s to be 'Hello World' with using the indxC. The indexes of c should be upper case in the string s. Can you help me thanks

채택된 답변

Image Analyst
Image Analyst 2020년 5월 25일
편집: Image Analyst 2020년 5월 25일
Try this:
indxC = [1,7];
s ='hello world';
s(indxC) = upper(s(indxC))
or more generally:
s ='hello world';
upperS = upper(s); % Create an ALL CAPITALS VERSION of s.
spaceLocations = find(s(1:end-1) == ' '); % Find spaces - we'll capitalize the location after a space.
spaceLocations = [0, spaceLocations] % Always capitalize the first letter, so prepend 0.
s(spaceLocations + 1) = upperS(spaceLocations + 1) % Replace these locations with upper case letters.
  댓글 수: 2
Umut Oskay
Umut Oskay 2020년 5월 25일
When i use the first one, s(indxC) is printed like HW, So just the indexes are printed not ‘Hello World’
Image Analyst
Image Analyst 2020년 5월 25일
After copying and pasting, this is what I get:
s =
'Hello World'
So I don't know what you mean when you say that just the indexes are printed, and not 'Hello World'. Please post a screenshot.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by