MATLAB: Making upper case character with respect to the indexes indexlowercase to uppercasestring arraystrings 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 Best Answer 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. Related SolutionsMATLAB: How to replace a certain word in a plain text s = 'This is the string. The goal is to replace the thes with as';newstr = regexprep(s, '\<the\>', 'a', 'preservecase');This matches only words, replacing 'the' with 'a', and when 'The' is matched it replaces with 'A' (conserving case) MATLAB: How to convert strings to a matrix This code takes in account more then one blanck spaces='Hello world's1=regexp(s,' ','split'); out=s1(~cellfun(@isempty ,s1)) Related QuestionFunction to capitalize first letter in each word in string but forces all other letters to be lowercaseCapitalize only the first letter of a characterRegexprep() skip first occurrenceSwap first and last word in a string
Best Answer