Answered step by step
Verified Expert Solution
Question
1 Approved Answer
MATLAB Find US state names that start with the letter N Write a function RemoveNStates that will remove all the states that start with the
MATLAB
Find US state names that start with the letter N Write a function RemoveNStates that will remove all the states that start with the letter N in a given a sentence containing US states. The function should remove remove all consecutive white space charaters from the start and the end of the output character array. The states that start with the letter N present in the sentence should be simply erased (i.e. leave additional spaces between the remaining words in output sentence, if needed they can be removed later). The input and output sentence will be a character array. You can assume the names of the states are spelled exactly as given in US states. Restrictions: The function may not use loops. The function should use the function erase and strtrim For example, >> s1 'Alabama Montana Nebraska Vermont Nevada's reducedList = RemoveNStates(s1) reducedList Alabama Montana Vermont Your Function Save Reset E MATLAB Documentation 1 function s2 = RemoveNStates (s1) 4851="Alabama Nebraska Montana Vermont Nevada"; 6 s3 strtrim(strsplit(s1))ssplit the s1 based on space and trim the white space 7 pat-"N".%the starting letter of the states you want to erase 8 T startswith(s3,pat)sthis will return the boolean matrix that contains 1 for matching states and 0 for n 9ab#53(T)%this will retrieve the states based on the boolean matrix which have value 1.i.e states start sw 10 s2-erase(s1,ab) 12 end Find US state names that start with the letter N Write a function RemoveNStates that will remove all the states that start with the letter N in a given a sentence containing US states. The function should remove remove all consecutive white space charaters from the start and the end of the output character array. The states that start with the letter N present in the sentence should be simply erased (i.e. leave additional spaces between the remaining words in output sentence, if needed they can be removed later). The input and output sentence will be a character array. You can assume the names of the states are spelled exactly as given in US states. Restrictions: The function may not use loops. The function should use the function erase and strtrim For example, >> s1 'Alabama Montana Nebraska Vermont Nevada's reducedList = RemoveNStates(s1) reducedList Alabama Montana Vermont Your Function Save Reset E MATLAB Documentation 1 function s2 = RemoveNStates (s1) 4851="Alabama Nebraska Montana Vermont Nevada"; 6 s3 strtrim(strsplit(s1))ssplit the s1 based on space and trim the white space 7 pat-"N".%the starting letter of the states you want to erase 8 T startswith(s3,pat)sthis will return the boolean matrix that contains 1 for matching states and 0 for n 9ab#53(T)%this will retrieve the states based on the boolean matrix which have value 1.i.e states start sw 10 s2-erase(s1,ab) 12 endStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started