Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

It dseon't mettar waht oedrr the lrettes in a wrod are. Write a function ScrambleLetters to take a phrase consisting of words and non-letters, identify

It dseon't mettar waht oedrr the lrettes in a wrod are.

Write a function ScrambleLetters to take a phrase consisting of words and non-letters, identify all the words (contain only letters) and then for all words reverse the subsequence of the letters leaving the first and the last letter of the word unchanged. The input phrase could be any length. The input sentence and output phrase should be a string scalar. For example:

>>inputString="Ones and 1 is sometimes two";

>>[outputString] = ScrambleLetters(inputString)

outputString =

"Oens and 1 is semitemos two"

image text in transcribed

inputString="Ones and 1 is sometimes two";[outputString] = ScrambleLetters(inputString)

Please try to fix this code so that I can get it right. I think it was wrong on the single quotation marks because the correct answer's single quotation marks should state the same. image text in transcribed

function [outputString] = ScrambleLetters(inputString)

inputStringMetaOne = not(inputString==' '); inputStringMetaTwo = isletter(inputString);

inputStringMeta = and(inputStringMetaOne,inputStringMetaTwo);

[indicator,startPositionOfAllOnes,endPositionOfAllOnes,lengthofAllOnes]=FindConsecutiveOnes(inputStringMeta);

for i = 1:length(startPositionOfAllOnes) word = inputString(startPositionOfAllOnes(i):endPositionOfAllOnes(i)); revWord = reverse(word); inputString(startPositionOfAllOnes(i):endPositionOfAllOnes(i))=revWord; end

outputString=inputString;

end

function sout = ReverseLetters(sin) sout = ''; if length(sin) == 1 sout(end + 1) = sin(1); else sout(end+1) = sin(1); for i = 1:length(sin)-2 if i sout(end + 1)= sin(length(sin) - i); else sout(end + 1) = sin(i); end end sout(end+1) = sin(end); end end

function [indicator,startPositionOfAllOnes,endPositionOfAllOnes,lengthofAllOnes] = FindConsecutiveOnes(inputArray) indicator = zeros(1, length(inputArray)); startPositionOfAllOnes=[]; endPositionOfAllOnes=[]; lengthofAllOnes=[]; j = 1; for i = 1 : length(inputArray) if i == 1 && inputArray(i) == 1 startPositionOfAllOnes(j) = i; elseif inputArray(i) == 1 && inputArray(i-1) == 0 startPositionOfAllOnes(j) = i; elseif i ~= 1 && inputArray(i) == 0 && inputArray(i-1) == 1 endPositionOfAllOnes(j) = i-1; lengthofAllOnes(j) = endPositionOfAllOnes(j) - startPositionOfAllOnes(j) + 1; j = j + 1; end end if inputArray(length(inputArray)) == 1 endPositionOfAllOnes(j) = length(inputArray); lengthofAllOnes(j) = endPositionOfAllOnes(j) - startPositionOfAllOnes(j) + 1; end for j = 1 : length(lengthofAllOnes)indicator(startPositionOfAllOnes(j)) = lengthofAllOnes(j); end end

image text in transcribedimage text in transcribed

Though your 0/ LAB 23.35.1: It dseon't mettar waht oedrr the Irettes in a wrod are. (Strings) Part 3 This toolis provided by a third party, ACTIVITY (final) of larger project Alfa activity may be recorded, a page refresh may be needed to fill the banner 15 It dseon't mettar waht oedrr the Irettes in a wrod are. Write a function ScrambleLetters to take a phrase consisting of words and non-letters, identify all the words (contain only letters) and then for all words reverse the subsequence of the letters leaving the first and the last letter of the word unchanged. The input phrase could be any ength. The input sentence and output phrase should be a string scalar. For example: >inputString- "Ones and 1 is sometimes two"; >> [outputstring] = ScrambleLetters (inputString) outputst ring = "0ens and 1 is semitemos two" Though your 0/ LAB 23.35.1: It dseon't mettar waht oedrr the Irettes in a wrod are. (Strings) Part 3 This toolis provided by a third party, ACTIVITY (final) of larger project Alfa activity may be recorded, a page refresh may be needed to fill the banner 15 It dseon't mettar waht oedrr the Irettes in a wrod are. Write a function ScrambleLetters to take a phrase consisting of words and non-letters, identify all the words (contain only letters) and then for all words reverse the subsequence of the letters leaving the first and the last letter of the word unchanged. The input phrase could be any ength. The input sentence and output phrase should be a string scalar. For example: >inputString- "Ones and 1 is sometimes two"; >> [outputstring] = ScrambleLetters (inputString) outputst ring = "0ens and 1 is semitemos two

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial Databases 2nd Symposium Ssd 91 Zurich Switzerland August 1991 Proceedings Lncs 525

Authors: Oliver Gunther ,Hans-Jorg Schek

1st Edition

3540544143, 978-3540544142

More Books

Students also viewed these Databases questions